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/useElementSize.md
1---2category: Elements3---45# useElementSize67Reactive size of an HTML element. [ResizeObserver MDN](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)89## Usage1011```vue12<script setup lang="ts">13import { useElementSize } from '@vueuse/core'14import { useTemplateRef } from 'vue'1516const el = useTemplateRef('el')17const { width, height } = useElementSize(el)18</script>1920<template>21<div ref="el">22Height: {{ height }}23Width: {{ width }}24</div>25</template>26```2728## Component Usage2930```vue31<template>32<UseElementSize v-slot="{ width, height }">33Width: {{ width }} Height: {{ height }}34</UseElementSize>35</template>36```3738## Directive Usage3940```vue41<script setup lang="ts">42import { vElementSize } from '@vueuse/components'4344function onResize({ width, height }: { width: number, height: number }) {45console.log(width, height)46}47</script>4849<template>50<textarea v-element-size="onResize" />51<!-- with options -->52<textarea v-element-size="[onResize, { width: 100, height: 100 }, { box: 'content-box' }]" />53</template>54```5556## Type Declarations5758```ts59export interface ElementSize {60width: number61height: number62}63export interface UseElementSizeOptions extends UseResizeObserverOptions {}64export interface UseElementSizeReturn {65width: ShallowRef<number>66height: ShallowRef<number>67stop: () => void68}69/**70* Reactive size of an HTML element.71*72* @see https://vueuse.org/useElementSize73*/74export declare function useElementSize(75target: MaybeComputedElementRef,76initialSize?: ElementSize,77options?: UseElementSizeOptions,78): UseElementSizeReturn79```80