splice刪除數(shù)組最后一項(xiàng)時(shí)報(bào)錯(cuò)<div class="content" :index='index'>
<p>確定要?jiǎng)h除品牌:{{tableList[index].name}} 嗎</p>
<button @click="del(index)">確定</button>
<button @click='cancel'>取消</button> </div>報(bào)錯(cuò)代碼:del:function(id){ this.tableList.splice(id,1) for(i=0;i<this.tableList.length;i++){ this.tableList[i].id = i+1
} this.show=false}報(bào)錯(cuò)數(shù)組: tableList:[
{id:1,name:'三只松鼠',timer:new Date()},
{id:2,name:'英菲尼迪',timer:new Date()},
{id:3,name:'杰克瓊斯',timer:new Date()},
{id:4,name:'雷蛇',timer:new Date()},
{id:5,name:'積家',timer:new Date()},
{id:6,name:'英偉達(dá)',timer:new Date()},
{id:7,name:'菲亞特',timer:new Date()}
]
去掉content中p標(biāo)簽的name則正常運(yùn)行
2 回答

斯蒂芬大帝
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
你這個(gè)報(bào)錯(cuò)是不是在你點(diǎn)擊“確定”的時(shí)候報(bào)的,如果是的話,是因?yàn)槟阍邳c(diǎn)擊確定把當(dāng)前行的數(shù)據(jù)刪除了,而你此時(shí)的彈框里的顯示數(shù)據(jù)也同步更新了,在找尋當(dāng)前索引下的name時(shí),沒有找到這個(gè)字段,所以報(bào)錯(cuò)了
添加回答
舉報(bào)
0/150
提交
取消