Skip to content

unrefElement

类别
导出体积
102 B
上次更改
7 months ago

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

用法

vue
<script setup lang="ts">
import { 
unrefElement
} from '@vueuse/core'
import {
onMounted
,
useTemplateRef
} from 'vue'
const
div
=
useTemplateRef
<HTMLElement>('div') // 将绑定到 <div> 元素
const
hello
=
useTemplateRef
<
Component
>('hello') // 将绑定到 HelloWorld 组件
onMounted
(() => {
console
.
log
(
unrefElement
(
div
)) // <div> 元素
console
.
log
(
unrefElement
(
hello
)) // HelloWorld 组件的根元素
}) </script> <template> <
div
ref
="
div
" />
<HelloWorld
ref
="
hello
" />
</template>

类型声明

ts
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
>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
IlyaL
Anthony Fu
SerKo
Henrik Kampshoff
Nebula
Julian Meinking
Jelf

更新日志

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)