vue3 使用Bus总线
ts +vue31. 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 Emitte
·
ts +vue3
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)
})
});
更多推荐
已为社区贡献18条内容
所有评论(0)