报错:[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:
在编写vue项目时经常会遇到在页面修改组件中的值时修改不了,但是console.log打印该组件对应的data属性值已经赋值成功,但页面就是不显示修改后的值,不过如果修改一下其他组件的值该组件的值就更新了。
当出现上方的错误时,有时是修改了父组件传入子组件的props,解决办法是在子组件的data中再定义一个属性(假如命名为temp)并将props中的值赋给该属性,组件的值使用该属性则修改组件值时就不会出现上方的错误了。
但是有时候并不是修改了props中的值的原因。发现一个解决办法是为该组件设置一个id并通过js的方法(document.getElementById("id").value=xxx)为其设值,就不会报上方的错误,页面组件的值也修改并显示成功了。
554

被折叠的 条评论
为什么被折叠?



