Page({
data: {
products: [
{name: 'A', quantity: 0},
{name: 'B', quantity: 0},
],
total: 0,
},
plus({currentTarget: {id}}) {
let {products, total} = this.data
let index = Number(id)
let {quantity} = products[index]
quantity += 1
total += 1
let key = `products[${index}].quantity`
console.log({key, quantity})
this.setData(
{
key: quantity,
total
},
() => {
console.log('quantity=', this.data.products[index].quantity)
}
)
}
})
点击按钮,total 正常,而商品数量始终为0。
不管对不对就硬回复是吧。
2、第二条为什么在你那没效果,你自己的问题吧