Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Event listener not firing in Vue

I want to toggle an element's visibility on keypress in Vue. The problem is I see the event is attached to the element but is not firing. the template is :

    <h1 v-show="typeWriterEffectVisible">
    <div id="game-board" data-v-d95dafd8="">
     <div class="letter-row">
      <div class="letter-box"></div>
      <div class="letter-box"></div>
      // etc

Vue:

<script setup>

let typeWriterEffectVisible = ref(true);

onMounted(() => {
   const el = document.querySelector(
    "#game-board > .letter-row:first-child > .letter-box:first-child"
  );

  // add eventlistener to toggle off typewriter effect on page
  el.addEventListener("keyup", () => {
    console.log("Im in toggle");
    typeWriterEffectVisible.value = false;
  }); 

From the DOM inspector I see the event is attached to the element but eventlistener callback is never invoked. If I change el.addEventListener to document.addEventListener it works. But then event fires on any keystroke on page which is not efficient or necessary. Any insights welcome...

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda