vue3 TypeScript 使用Bus总线
\1. main.ts 引入
import mitt from "mitt"
app.config.globalProperties.$bus = mitt();
2.在传数据里
import {Emitter} from 'mitt'
const {ctx: $this}: any = getCurrentInstance();
const bus = $this.$bus as Emitter;
//排序
const sortFun = (sortCase: string) => {
bus.emit('sortFun', sortCase)
}
3.在接数据里
import {Emitter} from 'mitt'
const {ctx: $this}: any = getCurrentInstance();
const bus = $this.$bus as Emitter;
onMounted(() => {
bus.on('sortFun', (e) => {
console.log(e)
})
});