Avoid Mutating A Prop Directly
I am getting warning: app.js:87486 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or c
Solution 1:
Initialise a data attribute from your prop, and manipulate that.
exportdefault {
data() {
return {
numberOfLikes: this.likescount
}
},
props: [
'isliked',
'path',
'type',
'likescount'
],
methods:{
like() {
axios.post(`/${this.type}/${this.path}/like/`);
// ...this.numberOfLikes++;
},
unlike() {
axios.post(`/${this.type}/${this.path}/unlike/`);
// ...this.numberOfLikes--;
},
}
}
Post a Comment for "Avoid Mutating A Prop Directly"