mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 18:01:24 +08:00
20 lines
371 B
TypeScript
20 lines
371 B
TypeScript
|
import { watch } from 'vue'
|
||
|
|
||
|
import type { Ref } from 'vue'
|
||
|
|
||
|
export const useToggleWidgets = (
|
||
|
watchSource: Ref<boolean>,
|
||
|
handler: (e: Event) => void
|
||
|
) => {
|
||
|
watch(
|
||
|
() => watchSource.value,
|
||
|
(val) => {
|
||
|
if (val) {
|
||
|
window.addEventListener('resize', handler)
|
||
|
} else {
|
||
|
window.removeEventListener('resize', handler)
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
}
|