Skip to content
On this page

unrefElement

Category
Last Changed
3 months ago

Unref for dom element.

Usage

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

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

const div = ref() // will be bind to the <div> element
const hello = ref() // will be bind 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>

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

const div = ref() // will be bind to the <div> element
const hello = ref() // will be bind to the HelloWorld Component

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

Type Declarations

export declare type VueInstance = ComponentPublicInstance
export declare type MaybeElementRef = MaybeRef<
  HTMLElement | SVGElement | VueInstance | undefined | null
>
/**
 * Get the dom element of a ref of element or Vue component instance
 *
 * @param elRef
 */
export declare function unrefElement(
  elRef: MaybeElementRef
): HTMLElement | SVGElement | undefined
export declare type VueInstance = ComponentPublicInstance
export declare type MaybeElementRef = MaybeRef<
  HTMLElement | SVGElement | VueInstance | undefined | null
>
/**
 * Get the dom element of a ref of element or Vue component instance
 *
 * @param elRef
 */
export declare function unrefElement(
  elRef: MaybeElementRef
): HTMLElement | SVGElement | undefined

Source

SourceDocs

Contributors

Anthony Fu

Changelog

v6.4.0 on 9/17/2021
9728a - fix(types): MaybeElementRef type, close #685
unrefElement has loaded