mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-13 17:05:47 +08:00
23 lines
436 B
TypeScript
23 lines
436 B
TypeScript
import { watch } from 'vue'
|
|
|
|
import { isClient } from '@vueuse/core'
|
|
import type { Ref } from 'vue'
|
|
|
|
export const useToggleWidgets = (
|
|
watchSource: Ref<boolean>,
|
|
handler: (e: Event) => void
|
|
) => {
|
|
if (!isClient) return
|
|
|
|
watch(
|
|
() => watchSource.value,
|
|
(val) => {
|
|
if (val) {
|
|
window.addEventListener('resize', handler)
|
|
} else {
|
|
window.removeEventListener('resize', handler)
|
|
}
|
|
}
|
|
)
|
|
}
|