mirror of
https://github.com/youzan/vant.git
synced 2025-10-15 15:40:52 +00:00
fix(@vant/use): allow to call useWindowSize outside setup (#9834)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { ref, Ref } from 'vue';
|
||||
import { inBrowser } from '../utils';
|
||||
import { useEventListener } from '../useEventListener';
|
||||
|
||||
let width: Ref<number>;
|
||||
let height: Ref<number>;
|
||||
@@ -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 };
|
||||
|
Reference in New Issue
Block a user