我正在尝试建立一个vue事件总线以在组件之间发送事件,我将其保存在app.js
文件Vue.prototype.$eventBus = new Vue();
中,然后在一个组件中将其保存
this.$eventBus.$emit('pnc-person', remarkString);
在安装的方法中的另一个组件中,我有这个
this.$eventBus.$on('pnc-person', (data) => {
console.log(data);
});
该事件已成功发出,我可以在vue开发工具中看到该事件,但是它没有被第二个组件捕获,我正在使用vue路由器,所以不确定是否会影响它。
我尝试同时使用this.$route.$on
和this.$eventBus.$on
,但似乎都没有记录任何内容
答案 0 :(得分:0)
也许当您的发射组件发送事件时,您的侦听组件尚未构建。
您是否尝试将this.$eventBus.$on
部分而不是created
中的mounted
中放置?