mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
24 lines
482 B
TypeScript
24 lines
482 B
TypeScript
|
import { watch } from 'vue'
|
||
|
import { on, off } from '@element-plus/utils/dom'
|
||
|
|
||
|
import type { Ref } from 'vue'
|
||
|
|
||
|
type Events = Array<{
|
||
|
name: string
|
||
|
handler: (...args: any[]) => any
|
||
|
}>
|
||
|
|
||
|
export default (el: Ref<HTMLElement>, events: Events) => {
|
||
|
events.map(({ name, handler }) => {
|
||
|
on(el.value, name, handler)
|
||
|
})
|
||
|
|
||
|
watch(el, (_, __, onCleanup) => {
|
||
|
onCleanup(() => {
|
||
|
events.map(({ name, handler }) => {
|
||
|
off(el.value, name, handler)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
}
|