Hi everyone I just want some explanation about vue props data. So I'm passing value from parent component to child component. The thing is when parent data has data changes/update it's not updating in child component.
Vue.component('child-component', {
template: '<div class="child">{{val}}</div>',
props: ['testData'],
data: function () {
return {
val: this.testData
}
}
});
But using the props name {{testdata}} it's displaying the data from parent properly
Vue.component('child-component', {
template: '<div class="child">{{testData}}</div>',
props: ['testData'],
data: function () {
return {
val: this.testData
}
}
});
Thanks in advance
Fiddle link
This is best explained with a very simple example
When you assign...
you're setting the initial value of
val
once when the component is created. Changes to the prop will not be reflected inval
in the same way that changes toa
above are not reflected inb
.See https://vuejs.org/v2/guide/components.html#One-Way-Data-Flow