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

370
Visualizações
Event listeners on elements in a Vue Modal: are they destroyed when the Modal is closed?

I'm adding an event listener for a DOM element in a component that exists within a Vue modal:

this.$bvModal.show('modal-upload-file')
this.$nextTick(() => {
        document.querySelector('#file').addEventListener('focus', () => {
          document.getElementsByClassName('file-uploads')[0].classList.add('btn-outline-primary')
          document.getElementsByClassName('file-uploads')[0].classList.remove('btn-primary')
        })
      })

The listener works great but I'd like to remove it when the Modal component closes; my application is an SPA and won't need it on other pages. Though I know that I can just use removeEventListener, my question is whether the event listeners are destroyed automatically when the Modal is closed since the elements inside the Modal no longer exist.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the node is destroyed (or removed from the DOM and never used again) then it'll be garbage collected along with any event listeners attached to it.

When using Vue, accessing the DOM manually and attaching event listeners like that is a red flag. Is there any reason why you can't do it the "Vue way"?

about 4 years ago · Juan Pablo Isaza Relatório
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