Skip to content

unrefElement

Category
Export Size
165 B
Last Changed
15 minutes ago

从 ref 或 Vue 组件实例中检索基础 DOM 元素。

用法

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

const div = ref() // 将绑定到 <div> 元素
const hello = ref() // 将绑定到 HelloWorld 组件

onMounted(() => {
  console.log(unrefElement(div)) // <div> 元素
  console.log(unrefElement(hello)) // HelloWorld 组件的根元素
})
</script>

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

类型声明

typescript
export type VueInstance = ComponentPublicInstance
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>
export type MaybeComputedElementRef<T extends MaybeElement = MaybeElement> =
  MaybeRefOrGetter<T>
export type MaybeElement =
  | HTMLElement
  | SVGElement
  | VueInstance
  | undefined
  | null
export type UnRefElementReturn<T extends MaybeElement = MaybeElement> =
  T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined
/**
 * 从 ref 或 Vue 组件实例中检索基础 DOM 元素。
 *
 * @param elRef
 */
export declare function unrefElement<T extends MaybeElement>(
  elRef: MaybeComputedElementRef<T>,
): UnRefElementReturn<T>

Source

SourceDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
Henrik Kampshoff
Nebula
Julian Meinking
Jelf

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue

Released under the MIT License.