unrefElement
unrefElement
Vueのrefまたはコンポーネントインスタンスから基になるDOM要素を取得します
使用法
<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>
© 2019–PRESENT Anthony Fu https://github.com/antfu
※このページは Nuxt.js 公式ドキュメントの翻訳ページです。
公式ドキュメントの該当ページはこちら:
#