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

134
Visualizações
Event handling in Vue.js

I have a situation where in an event is fired from parent component is being listen to by several child components.

e.g.
Parent Component: emit -> "orderReceived"
Child Component1( Tab1): on-> "orderReceived" -> fetch array1 from server
Child Component2( Tab2): on-> "orderReceived" -> fetch array2 from server

when both these tabs are opened, everything works fine. What I'm struggling with is, destroying event listeners on Tab1 and still be able to listen on Tab 2. ( when the tab1 is closed). Right now if the listeners of Tab1 are destroyed, it disables listeners on Tab 2 as well.

Thanks in advance.

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

0

The event must removed from component which was listening not both, You need to use $off, to just removed selected event, not all events from the specific component only, not to both

const ChildComponent1 = {
  methods:{
    orderReceived(){
      //orderReceived event emit
    }
  },
  created(){
    EventBus.$on('YOURCONTENT', this.orderReceived)
  },
  beforeDestroy(){
    EventBus.$off('YOURCONTENT', this.orderReceived)
  }
}
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