toElement
Resolves various element reference types to a plain DOM Element. Accepts refs, getters, raw DOM elements, or Vue component instances and normalizes them to a single Element | undefined.
Usage
import { toElement } from '@vuetify/v0'
import { useTemplateRef } from 'vue'
const el = useTemplateRef<HTMLDivElement>('target')
const element = toElement(el) // HTMLDivElement | undefinedArchitecture
toElement resolves multiple input shapes to a DOM element:
Supported Input Types
| Input | Result |
|---|---|
Ref<HTMLElement> | Unwrapped element |
ShallowRef<Element> | Unwrapped element |
() => HTMLElement | Called, returns element |
HTMLElement / SVGElement | Pass-through |
ComponentPublicInstance | Extracts $el |
null / undefined | Returns undefined |
Structural typing Uses { readonly value: T } instead of Vue’s nominal Ref<T> to avoid type mismatches across Vue versions.
Reactivity
toElement is a pure transformer function. It does not track reactivity or return reactive values.
Use inside computed for reactivity Wrap in computed() if you need reactive element resolution:
const resolved = computed(() => toElement(targetRef))Examples
FAQ
It extracts and returns the instance’s $el. Refs and getters are unwrapped, raw elements pass through, and null/undefined resolve to undefined.
To accept refs from any Vue version without nominal type mismatches — the structural shape matches a ref regardless of which Vue build produced it.
No. It resolves once when called. Wrap it in toRef(() => toElement(source)) to re-resolve whenever the source ref changes — useful when a target is null until after mount.