Skip to content

unrefElement

类别
导出体积
102 B
上次更改
1 hour 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
>

源码

源码文档

贡献者

一纸忘忧

更新日志

没有最近的更新日志