{"size": 589, "ext": "js", "max_stars_repo_path": "src/store/actions.js", "max_stars_repo_name": "huangshilin-gi/myshopping", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/actions.js", "max_issues_repo_name": "huangshilin-gi/myshopping", "max_issues_repo_issues_event_min_datetime": "2021-05-11T16:47:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-19T03:25:06.000Z", "max_forks_repo_path": "src/store/actions.js", "max_forks_repo_name": "huangshilin-gi/myshopping", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 29.45, "max_line_length": 88, "alphanum_fraction": 0.6298811545}
import {ADD_PRODUCT, ADD_CARTS} from './mutations_stype'
export default{
  addCart(context, carts){
    //为了严谨使用Promise 在组件中会获取res
    return new Promise((resolve)=>{
      //每一次查找 上一次的商品id是否和这一次的相等 
      let oldProduct = context.state.cartList.find(item => item.goodsId===carts.goodsId)
      //同一个商品 数量加1
      if(oldProduct){
        // oldProduct.count +=1 //因为被赋值为对象 所以可以直接再添加一个keys
        context.commit(ADD_PRODUCT,oldProduct)
        resolve('商品数量加1.');
      }else{
        carts.count = 1;
        context.commit(ADD_CARTS,carts)
        resolve('商品添加成功.')
      }
    })
  }
}