vue 下載包 npm install --save mitt
1.在main.js 里面
import mitt from "mitt";
const app = createApp(App);
app.config.globalProperties.$bus = mitt(); // 自定義添加
2.使用方法
(1)在任意一個頁面觸發 添加一個動態組件
this.$nextTick(function () {
this.$bus.emit("changeOdr", row.odrNo);
});
(2) 在動態組件里面
mounted() {
this.$bus.on("changeOdr", (key) => {
this.odrNo = key;
this.getData();
});
},
(3)
解決觸發多次問題 每當頁面關閉的時候 去銷毀這個事務線程 (還是在那個動態組件里面)【ps vue3.0 頁面銷毀生命周期是 beforeUnmount】
beforeUnmount() {
this.$bus.all.delete("changeOdr");
},