import{o as a,a as n,y as t}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=t(`
Get the viewport width and height of the browser window, and update it automatically when the window size changes.
import { watch } from 'vue';
import { useWindowSize } from '@vant/use';
export default {
setup() {
const { width, height } = useWindowSize();
console.log(width.value); // -> width of browser window
console.log(height.value); // -> height of browser window
watch([width, height], () => {
console.log('window resized');
});
},
};
function useWindowSize(): {
width: Ref<number>;
height: Ref<number>;
};
Name | Description | Type |
---|---|---|
width | The width of browser window | Ref<number> |
height | The height of browser window | Ref<number> |