When you add an event handler in the parent's mounted
lifecycle event for an event that is emitted in a child's mounted
event, the handler will not catch the event emitted by the child because the handler is added after the child has already emitted the event. Basically the cycle of events is like this.
- Parent's create
- Child's create
- Child's mounted
- Parent's mounted
Obviously there are other lifecycle events that occur, but that's the sequence that matters in this case.
If you want to handle an event emitted in the child, you need to create the handler (call $on) before the child's mounted
event.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…