Skip to content
On this page

useWindowSize

Category
Last Changed
3 months ago

Reactive window size

Demo

Infinity x Infinity

Usage

import { useWindowSize } from '@vueuse/core'

const { width, height } = useWindowSize()
import { useWindowSize } from '@vueuse/core'

const { width, height } = useWindowSize()

Component

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.
<UseWindowSize v-slot="{ width, height }">
  Width: {{ width }}
  Height: {{ height }}
</UseWindowSize>
<UseWindowSize v-slot="{ width, height }">
  Width: {{ width }}
  Height: {{ height }}
</UseWindowSize>

Type Declarations

export interface WindowSizeOptions extends ConfigurableWindow {
  initialWidth?: number
  initialHeight?: number
}
/**
 * Reactive window size.
 *
 * @see https://vueuse.org/useWindowSize
 * @param options
 */
export declare function useWindowSize({
  window,
  initialWidth,
  initialHeight,
}?: WindowSizeOptions): {
  width: Ref<number>
  height: Ref<number>
}
export declare type UseWindowSizeReturn = ReturnType<typeof useWindowSize>
export interface WindowSizeOptions extends ConfigurableWindow {
  initialWidth?: number
  initialHeight?: number
}
/**
 * Reactive window size.
 *
 * @see https://vueuse.org/useWindowSize
 * @param options
 */
export declare function useWindowSize({
  window,
  initialWidth,
  initialHeight,
}?: WindowSizeOptions): {
  width: Ref<number>
  height: Ref<number>
}
export declare type UseWindowSizeReturn = ReturnType<typeof useWindowSize>

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
Shinigami
wheat
Alex Kozack
Roman Pavlov

Changelog

v7.0.2 on 11/23/2021
42ae4 - fix: improve SSR
v4.11.2 on 5/30/2021
68c7d - feat(typedef): add return typedefs (#543) (#544)
v5.0.0-beta.2 on 5/25/2021
5bede - feat: introduce components & directives (#486)
useWindowSize has loaded