Can I emit from mounted in Wuijs?

I'm familiar with emitting data over the bus to events and they work great, but now I want to emit something, but I don't have an event to bind it.

I tried emitting it on mounted but it didn't work as shown below:

mounted(){
  bus.$emit('send-test', this.test);
},

      

-1


source to share


1 answer


When you add an event handler to the parent's lifecycle event mounted

for an event that is emitted in the child event mounted

, the handler will not catch the event emitted by the child, because the handler is added after the child has already selected the event. Basically, the event loop looks like this.

  • Parent creates
  • Child creates
  • Fixed child
  • Parental setting


Obviously, other life cycle events are happening, but the sequence that matters in this case.

If you want to handle an event fired on a child, you need to create a handler (call $ on) before the child event mounted

.

+4


source







All Articles