I am trying to pass data using provide and inject but the injected data is not reactive, can any help me to make it reactive.
//Parent.vue
<template>
{{ParentName}}
</template>
<script>
export default {
data(){
return{
ParentName: 'Initial Value'
}
}
provide() {
return {
name: this.ParentName,
};
},
}
</script>
I am changing the 'ParentName' after 3 sec using mounted hook'
mounted() {
setTimeout(() => {
this.ParentName = "New Name";
}, 3000);
},
In child component, i am injecting the value
//Child.vue
<template>
{{name}}
</template>
<script>
export default {
inject:['name']
}
</script>
But I am getting the injected name as 'Initial Value', not getting the updated value as "New Name" after 3 sec.