Skip to content

unrefElement

Category
Last Changed
9月12日17时50分

Retrieves the underlying DOM element from a Vue ref or component instance

Usage

vue
<script setup lang="ts">
import { unrefElement } from '@vueuse/core'
import { onMounted, useTemplateRef } from 'vue'

const div = useTemplateRef<HTMLElement>('div') // will be bound to the <div> element
const hello = useTemplateRef<Component>('hello') // will be bound to the HelloWorld Component

onMounted(() => {
  console.log(unrefElement(div)) // the <div> element
  console.log(unrefElement(hello)) // the root element of the HelloWorld Component
})
</script>

<template>
  <div ref="div" />
  <HelloWorld ref="hello" />
</template>

Source

SourceDocs

Changelog

v4.1.4 on 9/18/2025
5766d - feat: add useEventListener

Released under the MIT License.