Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue 2.0 instance is not hearing events emitted by vue-router components

I am using Vue 2.0-rc.6 (latest at the moment) and Vue-router 2.0-rc.5 (latest at the moment).

I tried to do this.$emit('custom-event') in one of my router components, and this.$on('custom-event', () => { console.log('I heard an event') }) in my Vue instance but the event was not being listened. The router component itself was hearing the event but not the Vue instance.

Any idea?

Check out this jsfiddle.

like image 891
Yapp Ka Howe Avatar asked Sep 14 '16 09:09

Yapp Ka Howe


1 Answers

An event from $emit is not propagated to the parent instance. The parent has to listen for it on the component in the template actively.

<router-view @eventname="callbackMethod" />
like image 68
DannyFeliz Avatar answered Oct 18 '22 14:10

DannyFeliz