Resize the box to see changes

useElementSize

Reactive size of an HTML element.

Usage

<template>
  <div ref="el">
    Height: {{ height }}
    Width: {{ Width }}
  </div>
</template>

<script>
import { ref } from 'vue'
import { useElementSize } from '@vueuse/core'

export default {
  setup() {
    const el = ref(null)
    const { width, height } = useElementSize(el)

    return {
      el,
      width,
      height,
    }
  }
})
</script>

ResizeObserver MDN

Type Declarations

export interface ElementSize {
  width: number
  height: number
}
/**
 * Reactive size of an HTML element.
 *
 * @see /useElementSize
 * @param target
 * @param callback
 * @param options
 */
export declare function useElementSize(
  target: MaybeElementRef,
  initialSize?: ElementSize,
  options?: ResizeObserverOptions
): {
  width: Ref<number>
  height: Ref<number>
}

Source

SourceDemoDocs