How to access this.$parent in vue 3 composition api ? I need to access the parent component props and data but seems like with vue 3 composition setup api its not available , please suggest an alternative #9490
Unanswered
maersk-ps
asked this question in
Help/Questions
Replies: 2 comments 5 replies
-
Use <script lang="ts" setup>
import { onMounted, getCurrentInstance } from 'vue';
onMounted(() => {
const instance = getCurrentInstance();
console.log(instance.parent.props);
});
</script>
<template>
<div></div>
</template> |
Beta Was this translation helpful? Give feedback.
2 replies
-
You use provide/inject |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to migrate from vue 2 to vue 3 and while doing that I encountered a code where I was using
this.$parent
in old code .Parent component template:
Child component template:
Now the above line needs to be changed to vue 3 composition api setup
I tried
getCurrentInstance
, but seems like it is an internal api and not officially documented .Provide/Inject
seems to be too much as I have only one prop to be accessed.Basically I need to know how can we access the parent component in vue 3 composition api
OR
How to replace this.$parent in vue 3 composition
Any suggestions ?
Beta Was this translation helpful? Give feedback.
All reactions