版本
"mitt": "^3.0.1"
1、npm install mitt
2、项目下创建文件夹eventBus 建 myEventBus.js
import mitt from 'mitt'
export default mitt()
3、组件里监听
组件A
import myEventBus from "../eventBus/myEventBus";
myEventBus.on('closeVisit',()=>{ // closeVisit 名称
// 逻辑
closeOpen()
})
组件B
import myEventBus from "../eventBus/myEventBus";
myEventBus.emit('closeVisit')
标签:myEventBus,closeVisit,mitt,vue3,组件,import,eventBus From: https://www.cnblogs.com/luckyShuang/p/17879112.html