我有一个简单的 Vue 组件,其根元素为ref="divRef"
. 但是,在onMounted
函数中,divRef.value
返回未定义。任何帮助将不胜感激。
import { defineComponent, onMounted, ref, Ref, h } from "vue"
export default defineComponent({
setup(props, context) {
const divRef = ref() as Ref<HTMLElement>
onMounted(() => {
console.log(divRef.value) // undefined
})
return () => {
return h(
"div",
{
ref: "divRef"
},
"This is a div"
)
}
}
})