-海深不蓝森浓不绿 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 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度