I am facing an issue with my Vue component wherein the root element is set as ref="divRef"
. Strangely, when I try to access divRef.value
inside the onMounted
function, it returns undefined. Any assistance on this matter would be greatly appreciated.
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"
)
}
}
})