vue报错:

Avoid mutating a prop directly since the value will be overwritten whenever

官方文档

所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件中,但是反过来则不行。

错误代码:

父组件:
error3.png
子组件:

1
2
3
4
5
cancelReply() {
this.parentId = "0";
this.replyuserName = "";
this.isReply = false;
}

解决方法

子组件:

1
2
3
4
5
cancelReply() {
this.$emit('changereplyuserName',"");
this.$emit('changeparentId',"0");
this.$emit('changeisReply',false);
}

父组件:
error4.png