MCPcopy Create free account
hub / github.com/coderwhy/HYMiniMall / addToCart

Function addToCart

app.js:5–20  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

3 onLaunch: function () {
4 },
5 addToCart(obj) {
6 // 1.判断是否已经添加进来
7 const oldInfo = this.globalData.cartList.find((item) => item.iid === obj.iid)
8 if (oldInfo) {
9 oldInfo.count += 1
10 } else {
11 obj.count = 1
12 obj.checked = true
13 this.globalData.cartList.push(obj)
14 }
15
16 // 2.购物车回调
17 if (this.addCartCallback) {
18 this.addCartCallback()
19 }
20 },
21 globalData: {
22 cartList: []
23 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected