在vue父組件傳遞數(shù)據(jù)給子組件時(shí)候,通過(guò)雙向綁定給屬性賦值時(shí)候,報(bào)錯(cuò)如下: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: "content"
1、報(bào)錯(cuò)詳情 [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: "items_index"
2、錯(cuò)誤原因
改動(dòng)了子組件中引用的父組件的變量,也就是props中的數(shù)據(jù)
在Vue2中組件props中的數(shù)據(jù)只能單向流動(dòng),即只能從父組件通過(guò)組件的DOM屬性attribute傳遞props給子組件,子組件只能被動(dòng)接收父組件傳遞過(guò)來(lái)的數(shù)據(jù),并且在子組件中,不能修改由父組件傳來(lái)的props數(shù)據(jù)。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-652217.html
3、解決方案avoid mutating a prop directly since the value will be overwritten whenever
不要直接修改從父組件傳過(guò)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-652217.html
到了這里,關(guān)于avoid mutating a prop directly since the value will be overwritten whenever完美解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!