Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useWindowSize.md
1---2category: Elements3---45# useWindowSize67Reactive window size89## Usage1011```vue12<script setup lang="ts">13import { useWindowSize } from '@vueuse/core'1415const { width, height } = useWindowSize()16</script>1718<template>19<div>20Width: {{ width }}21Height: {{ height }}22</div>23</template>24```2526## Component Usage2728```vue29<template>30<UseWindowSize v-slot="{ width, height }">31Width: {{ width }}32Height: {{ height }}33</UseWindowSize>34</template>35```3637## Type Declarations3839```ts40export interface UseWindowSizeOptions extends ConfigurableWindow {41initialWidth?: number42initialHeight?: number43/**44* Listen to window `orientationchange` event45*46* @default true47*/48listenOrientation?: boolean49/**50* Whether the scrollbar should be included in the width and height51* Only effective when `type` is `'inner'`52*53* @default true54*/55includeScrollbar?: boolean56/**57* Use `window.innerWidth` or `window.outerWidth` or `window.visualViewport`58* visualViewport documentation from MDN(https://developer.mozilla.org/zh-CN/docs/Web/API/VisualViewport)59* @default 'inner'60*/61type?: "inner" | "outer" | "visual"62}63export interface UseWindowSizeReturn {64width: ShallowRef<number>65height: ShallowRef<number>66}67/**68* Reactive window size.69*70* @see https://vueuse.org/useWindowSize71* @param options72*73* @__NO_SIDE_EFFECTS__74*/75export declare function useWindowSize(76options?: UseWindowSizeOptions,77): UseWindowSizeReturn78```79