微信小程序商品加入购物车js里逻辑是什么样的
新人刚入小程序
请路过的大佬 解释下!!!
需要调用小程序端的API吗?getStorageSync
不是很明白。
找的源码:
cart:function(e){//加入购物车
var that=this;
var id = e.currentTarget.dataset.id;
var userId = wx.getStorageSync('userId');
if (userId != null && userId > 0 && userId != '') {
that.addCart(id, userId, that.data.quantity, 1, e.currentTarget.dataset.unit);
}else{
wx.showModal({
title: '温馨提示',
content: '先登录',
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/mine/mine',
})
} else if (res.cancel) {
}
}
})
}
}