一分钟搞定vue全局注册事件eventBus

全局注册事件只适合中小型项目。

main.js中:
1.Vue.prototype.$EventBus = new Vue(); //全局的事件总线

  

任何组件
2.全局注册事件 this.$EventBus.$emit("abudaren", {num: 4});

  

任何组件
3 监听事件 this.$EventBus.$on("abudaren", ({ num }) => { this.$nextTick(() => { console.log("接收到的num为:",num) }); });

  结束战斗,希望没有超过一分钟。

posted @ 2019-12-26 16:11  阿布大人  阅读(4343)  评论(0编辑  收藏  举报