testData: [
{ id: 1, title: '测试1' },
{
id: 2,
title: '测试2'
},
{
id: 3,
title: '测试3'
}
]
<view class="" v-for="n in 10" :key="n" @tap="testTap(n)">{{ n }}</view>
<view class="" v-for="item in testData" :key="index" @tap="testTap2(item)">{{ item.title }}</view>
testTap(item) {
console.log(item);
直接报错: //VM3859:1 thirdScriptError
Cannot read property '2' of undefined; [Component] Event Handler Error @ pages/cost-list/cost-list#handleEvent
TypeError: Cannot read property '2' of undefined
},
testTap2(item) {
console.log(item);
打印 //undefined
},
uni-app 小程序端 v-for循环绑定事件@event="func(item)"传值触发时打印item为undefined
使用 :key="item.id" 报这个错误,但是 data-id="item.id" 中有值。按照你这个方法把 :key="item.id" 改成 :key="index" 就好了