vue3-eventbus
vue3-eventbus copied to clipboard
A friendly event bus for Vue3
```js import $EventBus from 'vue3-eventbus'; onMounted(()=>{ $EventBus.on('aaa',()=>{ // 一些方法 }) }) onBeforeUnmount(()=>{ $EventBus.off('aa'); // 这里不能取消订阅,只能采用具名函数的方式去取消; }) ``` > 上面的方法不能取消订阅,导致可能会多次触发订阅机制;
[https://github.com/developit/mitt](url)
Could not find a declaration file for module 'vue3-eventbus'. Try `npm i --save-dev @types/vue3-eventbus` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue3-eventbus';`
const MCDialogWrapRef = ref(null); bus.on("MCStatus-seeReason", ({ item, index }) => { console.log(item, index); console.log(MCDialogWrapRef, "dialogWrapRef-1"); reasonRejec.value = "拒绝了"; if (MCDialogWrapRef) MCDialogWrapRef.value.show = true; }); 获取不到爷爷组件的ref