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/unrefElement.md
1---2category: Component3---45# unrefElement67Retrieves the underlying DOM element from a Vue ref or component instance89## Usage1011```vue12<script setup lang="ts">13import { unrefElement } from '@vueuse/core'14import { onMounted, useTemplateRef } from 'vue'1516const div = useTemplateRef('div') // will be bound to the <div> element17const hello = useTemplateRef('hello') // will be bound to the HelloWorld Component1819onMounted(() => {20console.log(unrefElement(div)) // the <div> element21console.log(unrefElement(hello)) // the root element of the HelloWorld Component22})23</script>2425<template>26<div ref="div" />27<HelloWorld ref="hello" />28</template>29```3031## Type Declarations3233```ts34export type VueInstance = ComponentPublicInstance35export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>36export type MaybeComputedElementRef<T extends MaybeElement = MaybeElement> =37MaybeRefOrGetter<T>38export type MaybeElement =39| HTMLElement40| SVGElement41| VueInstance42| undefined43| null44export type UnRefElementReturn<T extends MaybeElement = MaybeElement> =45T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined46/**47* Get the dom element of a ref of element or Vue component instance48*49* @param elRef50*/51export declare function unrefElement<T extends MaybeElement>(52elRef: MaybeComputedElementRef<T>,53): UnRefElementReturn<T>54```55