Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda