-海深不蓝森浓不绿 2019-08-23 19:03 采纳率: 0%
浏览 1297

微信小程序商品加入购物车逻辑

微信小程序商品加入购物车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) {
                    }
                }
            })
        }
    }

图片说明

  • 写回答

1条回答 默认 最新

  • hou1988426 2023-06-08 17:30
    关注

    getStorageSync 是获取小程序之前存储的 userId 通过 wx.getStorageSync('userId') 赋给变量 var userId
    至于

    if (userId != null && userId > 0 && userId != '') {
                that.addCart(id, userId, that.data.quantity, 1, e.currentTarget.dataset.unit); //这里是添加购物车的 另一个addCart方法函数
     }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置