Skip to content
On this page

useWindowSize

Category
Last Changed
2 weeks 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 Usage

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
  /**
   * Listen to window `orientationchange` event
   *
   * @default true
   */
  listenOrientation?: boolean
}
/**
 * Reactive window size.
 *
 * @see https://vueuse.org/useWindowSize
 * @param options
 */
export declare function useWindowSize(options?: WindowSizeOptions): {
  width: Ref<number>
  height: Ref<number>
}
export declare type UseWindowSizeReturn = ReturnType<typeof useWindowSize>
export interface WindowSizeOptions extends ConfigurableWindow {
  initialWidth?: number
  initialHeight?: number
  /**
   * Listen to window `orientationchange` event
   *
   * @default true
   */
  listenOrientation?: boolean
}
/**
 * Reactive window size.
 *
 * @see https://vueuse.org/useWindowSize
 * @param options
 */
export declare function useWindowSize(options?: WindowSizeOptions): {
  width: Ref<number>
  height: Ref<number>
}
export declare type UseWindowSizeReturn = ReturnType<typeof useWindowSize>

Source

SourceDemoDocs

Contributors

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

Changelog

v8.8.0 on 7/6/2022
c3f95 - feat: listen to the orientationchange event (#1609)
v7.0.2 on 11/23/2021
42ae4 - fix: improve SSR
useWindowSize has loaded