關於vue中Cannot read property ‘key‘ of undefined 的解決
阿新 • • 發佈:2021-02-07
報錯圖:
原因及解決辦法:
就是因為":starNum=" 的值應該是number型,為空時我傳遞一個String型的 ‘0’,應該為number型的 0
導致迴圈中starNum 被使用,類似 v-for="(item,index) in starNum" :key= “index”
key就報錯了.
key的報錯,一般就是用到key了,或者就是v-for裡的 :key 的問題
原始碼:
<SubHeader
headerText="技術"
: starNum="
stockTechnology.subitem_score
? stockTechnology.subitem_score.toFixed(0) * 1
: '0'
"
theme="blue"
/>
修改後:
<SubHeader
headerText="技術"
:starNum="
stockTechnology.subitem_score
? stockTechnology.subitem_score.toFixed (0) * 1
: 0
"
theme="blue"
/>