diff --git a/packages/vant-use/src/useWindowSize/index.ts b/packages/vant-use/src/useWindowSize/index.ts index 02230d56c..5a17ba64b 100644 --- a/packages/vant-use/src/useWindowSize/index.ts +++ b/packages/vant-use/src/useWindowSize/index.ts @@ -1,6 +1,5 @@ import { ref, Ref } from 'vue'; import { inBrowser } from '../utils'; -import { useEventListener } from '../useEventListener'; let width: Ref; let height: Ref; @@ -10,16 +9,16 @@ export function useWindowSize() { width = ref(0); height = ref(0); - const update = () => { - if (inBrowser) { + if (inBrowser) { + const update = () => { width.value = window.innerWidth; height.value = window.innerHeight; - } - }; + }; - update(); - useEventListener('resize', update); - useEventListener('orientationchange', update); + update(); + window.addEventListener('resize', update, { passive: true }); + window.addEventListener('orientationchange', update, { passive: true }); + } } return { width, height };