chore: save
This commit is contained in:
@@ -2,11 +2,27 @@ import {onMounted, onUnmounted} from "vue";
|
||||
import {emitter, EventKey} from "@/utils/eventBus.ts";
|
||||
|
||||
export function useWindowClick(cb: () => void) {
|
||||
onMounted(() => {
|
||||
emitter.on(EventKey.closeOther, cb)
|
||||
window.addEventListener('click', cb)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('click', cb)
|
||||
})
|
||||
onMounted(() => {
|
||||
emitter.on(EventKey.closeOther, cb)
|
||||
window.addEventListener('click', cb)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('click', cb)
|
||||
})
|
||||
}
|
||||
|
||||
export function useEventListener(type: string, listener: EventListenerOrEventListenerObject) {
|
||||
onMounted(() => window.addEventListener(type, listener))
|
||||
onUnmounted(() => window.removeEventListener(type, listener))
|
||||
}
|
||||
|
||||
export function useEsc(can: boolean) {
|
||||
onMounted(() => {
|
||||
window.addEventListener('keyup', (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && can) {
|
||||
close()
|
||||
}
|
||||
})
|
||||
})
|
||||
return []
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import {onMounted} from "vue"
|
||||
|
||||
export function useEsc(can: boolean) {
|
||||
onMounted(() => {
|
||||
window.addEventListener('keyup', (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && can) {
|
||||
close()
|
||||
}
|
||||
})
|
||||
})
|
||||
return []
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// event.js
|
||||
import {onMounted, onUnmounted} from 'vue'
|
||||
|
||||
export function useEventListener(type: string, listener: EventListenerOrEventListenerObject) {
|
||||
onMounted(() => window.addEventListener(type, listener))
|
||||
onUnmounted(() => window.removeEventListener(type, listener))
|
||||
}
|
||||
Reference in New Issue
Block a user