现有vue-router的一个webapp,有一个聊天页面进入后连接socket,切换到其他路由后,监听客户发过来的消息,在页面上面提示用户。我在聊天路由中使用this.$dispatch('admin_msg_notify')
,在主路由中使用
let App = Vue.extend({
events: {
//消息通知
admin_msg_notify : 'showMsgToast'
},
methods : {
showMsgToast(){
console.log('主屏幕来消息了');
$.toast('消息来了')
}
}
});
router.start(App,'#app');
监听不到消息通知?
路由组件的$parent 是null 所以获取不到
使用vue-router的属性