Write a judgment sentence with vue framework to judge that when goods are added to a shopping cart, the quantity of the same kind of goods is added, and there can be no two records of the same kind of goods.

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

  1. I write
like this

/ / 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.:
Jun.29,2021
Menu