购物车加入问题?
参考https://cloud.tencent.com/edu/learning/learn-1482-8557 里面的教程,购物车加1的问题。 谢谢解答! [图片] const app = getApp()
const db = wx.cloud.database()
Page({
data: {
list:[],
tops:[]
},
addCart(e) {
const {item} = e.currentTarget.dataSet
const i = app.globalData.carts.findIndex(v => v._id == item._id)
if (i>-1) {
//数量加1
app.globalData.carts[i].num += 1
} else {
item.num = 1
app.globalData.carts.push(item)
}
},