useResizeObserver
A composable for detecting element size changes using the Resize Observer API with automatic cleanup.
Usage
The useResizeObserver composable wraps the Resize Observer API to detect when an element’s dimensions change. It’s useful for responsive components, charts, virtualized lists, and aspect ratio maintenance.
UseResizeObserver
<script setup lang="ts">
import { useResizeObserver } from '@vuetify/v0'
import { ref, useTemplateRef } from 'vue'
const container = useTemplateRef('container')
const width = ref(0)
const height = ref(0)
useResizeObserver(container, (entries) => {
const entry = entries[0]
width.value = entry.contentRect.width
height.value = entry.contentRect.height
})
</script>
<template>
<div ref="container" class="resizable">
<p>Width: {{ width }}px</p>
<p>Height: {{ height }}px</p>
</div>
</template>Examples
Responsive Grid
A resizable container that adapts its grid layout based on observed dimensions.
0 x 0
Analytics
Users
Revenue
Orders
Messages
Settings
Drag the right edge to resize. Columns: 1
Architecture
useResizeObserver wraps the native ResizeObserver API with Vue reactivity:
The following API details are for the useResizeObserver composable.
Functions
useResizeObserver
(target: MaybeRef<Element>, callback: (entries: ResizeObserverEntry[]) => void, options?: ResizeObserverOptions) => UseResizeObserverReturnA composable that uses the Resize Observer API to detect when an element's size changes.
useElementSize
(target: MaybeRef<Element>) => UseElementSizeReturnA convenience composable that uses the Resize Observer API to track an element's size.
Options
Properties
isActive
Readonly<Ref<boolean, boolean>>Whether the observer is currently active (created and observing)
Methods
Was this page helpful?
