我声明数组为
const myproducts = ref([] )
之后,我将value压入数组。myproducts
就像
[ { "id": 1, "qty": 1 }, { "id": 7, "qty": 1 } ]
var old_qty = myproducts.value.find(x => x.id === id).qty
var new_qty = old_qty +1
如何在id为1的数组中添加new_qty ?
TIA
var old_qty = myproducts.value.find(x => x.id === id).qty
var new_qty = old_qty +1
myproducts.value.find(x => x.id === id).qty = new_qty
或
myproducts.value.find(x => x.id === id).qty+=1;