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)
   })
});

 

Logo

前往低代码交流专区

更多推荐