1.安装bus
npm install vue-bus
2.main.js引入bus
import VueBus from 'vue-bus';
Vue.use(VueBus);
3.触发事件
this.$bus.emit("setting", 9);
4.监听事件
created() {
this.$bus.on("setting", (data) => {
this.current = data;
});
},
5.销毁事件
destroyed() {
this.$bus.off("setting", this.current);
},