Passing Data From Props To Data In Vue.js
I have the following vue component:
Solution 1:
It sounds like you want to modify just a few of the options in your chartOptions
object and pass them as to your CommitChart
component.
exportdefault {
props:["label","data"],
data() {
return {
chartOptions: {...},
}
},
computed:{
commitChartOptions(){
let localOptions = Object.assign({}, this.chartOptions)
localOptions.datasets[0].label = this.label;
localOptions.datasets[0].data = this.data;
return localOptions;
}
}
}
And then in your template, use the commitChartOptions
computed.
<CommitChart :data="commitChartOptions"></Commitchart>
Here is an example demonstrating the concept.
Solution 2:
export default {
props: ['label'],
data () {
return {
anotherLabel: this.label, // you cannot use the same name as declared for props
}
}
}
Solution 3:
let assume:
labels
is data and
label
is props
then use this to copy:
this.labels = { ...this.label };
Post a Comment for "Passing Data From Props To Data In Vue.js"