author:
date: 2021.07.03
文章目录
1. 需求及报错
需求: 使用的场景是:A 组件中引用 B 组件,使用 v-model
给 B 传递参数,B 使用 props: { value }
接收内容,在 B 中根据逻辑直接修改并赋值 value
, 事件触发后在浏览器 console 里看到报错,内容如下:
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders.
Instead, use a data or computed property based on the prop's value. Prop being mutated: "value"