N
N
newitem2021-06-04 10:54:55
Vue.js
newitem, 2021-06-04 10:54:55

Why does $emit send 1 event and 2 arrive?

Hello.
I want to send an event to the bus on the esc button.
I do it like this

@keyup.esc="busSend"

 busSend() {
      bus.$emit('tableCell',{
        nodeData:this.nodeData
      })
    }

Displayed console.log before sending, it is displayed 1 time.

In another component, I start listening to created and it already gives out the data object 2 times

bus.$on("tableCell", data => {
console.log(data)
      });


I can't put once because I need to listen to this event more than once

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kulakov, 2021-06-04
@kulakoff Vue.js

It seems that there are only two options - busSend fires twice, or the subscription to this event occurs twice. Insert a console.log before bus.$on to check how many times the subscription occurs.

V
Vladimir Sartakov, 2021-06-06
@Arhangel7b

You need to unsubscribe in the destroyed hook or before subscribing:
bus.$off("tableCell")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question