mirror of
https://gitee.com/vant-contrib/vant.git
synced 2026-07-06 22:57:16 +08:00
27 lines
559 B
TypeScript
27 lines
559 B
TypeScript
import { ref, Ref } from 'vue';
|
|
import { inBrowser } from '../utils';
|
|
import { useEventListener } from '../useEventListener';
|
|
|
|
let width: Ref<number>;
|
|
let height: Ref<number>;
|
|
|
|
export function useWindowSize() {
|
|
if (!width) {
|
|
width = ref(0);
|
|
height = ref(0);
|
|
|
|
const update = () => {
|
|
if (inBrowser) {
|
|
width.value = window.innerWidth;
|
|
height.value = window.innerHeight;
|
|
}
|
|
};
|
|
|
|
update();
|
|
useEventListener('resize', update);
|
|
useEventListener('orientationchange', update);
|
|
}
|
|
|
|
return { width, height };
|
|
}
|