vue bus通信
const eventBus = { install(Vue,options) { Vue.prototype.$bus = vue } }; Vue.use(eventBus);
methods: { //分发事件
todo: function () {
this.$bus.$emit('todoSth', params);
}
}
created() { this.$bus.$on('todoSth', (params) => { //todo something }) }, // 在组件销毁前 // 清除事件监听 beforeDestroy () { this.$bus.$off('todoSth'); }

浙公网安备 33010602011771号