vue props 单项数据流 和 双向绑定

984 阅读1分钟
[Vue warn]: 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: "NClassLoading"


问题:子组件获取到父组件 ‘NClassLoading’ 参数, 在子组件内通过 v-model 绑定 ‘NClassLoading’。

问题原因:v-model 绑定的对象无法是props 接受到的

解决办法:在子组件内data 中重新赋值一下


同理:对于一个数组或对象类型的 prop 来说,在子组件中改变这个对象或数组本身将会影响到父组件的状态