toggle-widgets.ts 480 B

12345678910111213141516171819
  1. import { watch } from 'vue'
  2. import { isClient } from '@vueuse/core'
  3. import type { Ref } from 'vue'
  4. export const useToggleWidgets = (watchSource: Ref<boolean>, handler: (e: Event) => void) => {
  5. if (!isClient) return
  6. watch(
  7. () => watchSource.value,
  8. val => {
  9. if (val) {
  10. window.addEventListener('resize', handler)
  11. } else {
  12. window.removeEventListener('resize', handler)
  13. }
  14. }
  15. )
  16. }