Vue 3 get parent component
Version
3.2.6
Reproduction link
Steps to reproduce
In Vue 2, we can get parent element like this:
this.$vnode.elm.parentElement
What is expected?
It gives parent element
What is actually happening?
TypeError: Cannot read property 'elm' of undefined
What does $vnode equal in Vue 2
$vnode was always internal thing, it's better to just use refs to grab DOM element
<script setup>
import { ref, onMounted } from 'vue'
const root = ref(null)
onMounted(() => {
console.log(root.value.parentElement)
})
</script>
<template>
<div ref="root">
</div>
</template>