vue2中
import Vue from 'vue'
const bus = new Vue()
Vue.prototype.$bus = bus
this.$bus感觉世界都是我的
vue3
import mitt from 'mitt';
const app = createApp(App)
// 把插件的 API 挂载全局变量到实例上
app.config.globalProperties.$bus = mitt();
每次用的时候
import { defineComponent, getCurrentInstance } from 'vue'
const app = getCurrentInstance();
app.appContext.config.globalProperties.$bus
像吃了翔一样的难受,还我好用的全局变量挂载方案!!!