useResizeObserver

Commons
stable

Wraps the native ResizeObserver API with a reactive template ref. Returns a resizeRef to attach to any element and a readonly contentRect that updates on every resize. Automatically disconnects the observer on component unmount. Supports both content-box (default) and border-box measurement.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

Interfaces consommées

IResizeState

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

callback
ResizeObserverCallback
Optional raw ResizeObserver callback. Receives the full entries array and the observer instance. Called on every resize event before contentRect is updated.
box
'content' | 'border'
'content'
Which box model dimension to capture. "content" uses entries[0].contentRect; "border" calls getBoundingClientRect() on the element for border-box dimensions including padding and border.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

resizeRef
Assign this ref to the element you want to observe: <div :ref="resizeRef">. Watching the ref automatically connects/disconnects the observer.
contentRect
Reactive dimensions of the observed element. undefined until the first resize event fires. Provides width, height, top, left, right, bottom.

Usage

Exemples

Extraits de code prêts à coller.

Track element dimensions reactively

vue

Custom callback + border-box

vue