I want to set data of dynamic component from the parent component
For example : Parent Component :
<div id="app">
<template v-for="(component, index) in components">
<component :is="component" :key="index"></component>
</template>
<button @click="add()">Add Component</button>
</div>
Dynamic Component :
let dynamicComponent = {
template: `
<p>Welcome {{ msg }}!</p>
`,
data () {
return {
msg: 'home'
}
},
}
const App = new Vue({
el: '#app',
data: {
components: [
dynamicComponent
]
},
methods: {
add () {
this.components.push(dynamicComponent);
},
}
});
I want to set the data of the dynamic component from the parent component when the new dynamic component is added.
In this case, the msg property of dynamicComponent from the parent component