This commit is contained in:
zyronon
2024-06-04 00:34:45 +08:00
parent 0d3ad66a9f
commit 757eab6928
8 changed files with 109 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
import mitt from 'mitt'
import {onMounted, onUnmounted} from "vue";
export const emitter = mitt()
export const EventKey = {
@@ -19,4 +20,14 @@ export const EventKey = {
editDict: 'editDict',
openMyDictDialog: 'openMyDictDialog',
jumpSpecifiedChapter: 'jumpSpecifiedChapter',
}
export function useEvent(key: string, func: () => void) {
onMounted(() => {
emitter.on(key, func)
})
onUnmounted(() => {
emitter.off(key, func)
})
}