2016-09-14 39 views
9

我正在使用Vue 2.0-rc.6(最新的當前版本)和Vue-router 2.0-rc.5(最新版本)。Vue 2.0實例沒有聽到vue-router組件發出的事件

我試圖在我的一個路由器組件中執行this.$emit('custom-event'),在我的Vue實例中嘗試執行this.$on('custom-event',() => { console.log('I heard an event') }),但事件未被監聽。路由器組件本身聽到事件,但不是Vue實例。

有什麼想法?

看看這個jsfiddle

+0

我已經更新了你的提琴積極傾聽它的組件上:https://jsfiddle.net/wanxe/vnj71j8f/1/ https://開頭vuejs。 org/guide/components.html#Non-Parent-Child-Communication(感謝Mani:http://stackoverflow.com/questions/40377977/how-to-create-a-hook-with-events-between-vue- 2-0-組件/ 40378611?noredirect = 1個#comment68012089_40378611) – jnieto

回答

10

來自$ emit的事件不會傳播到父實例。 的父或母,有模板

<router-view @eventname="callbackMethod">