关于使用跨组件通信

3 阅读1分钟

vue2

在main.js内注册事件总线

import bus from './bus.js'
Vue.prototype.$bus = bus

在需要接收事件的组件内

this.$bus.$on("xxx", () => {})

在需要向外传递事件的组件内 同一般的子传父

this.$bus.$emit("xxx",val)