1. Problem: write a judgment sentence with vue framework to judge that when goods are added to a shopping cart, the quantity of the same item is added, and two records cannot appear for the same item
- I write
/ / add to the shopping cart
addShopcart(item, index) {
function getUniqueKey(item) {
return "" + goods.sku_code + goods.sku_id;
}
let goods = $global.deepCopy(item);
let isEqual = false;
for(let i = 0; i < this.list.length; iPP) {
if(getUniqueKey(this.list[i]) === getUniqueKey(goods)) {
isEqual = true;
this.list[i].item.amount = Number(this.list[i].item.amount);
this.list[i].item.amount += Number(this.list[i].item.amount);
break;
}
if(!isEqual) {
this.list.push(goods);
}
let user_id=localM.get("user_id");
localM.set(user_id+"shopcartList", this.list, true);
Message.success({message: "", center: true});
}
},
3.: