FWQ
微信小程序商城开发之实现商品加入购物车的功能(代码)
本篇文章给大家带来的内容是关于微信小程序商城开发之实现商品加入购物车的功能(代码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。 看效果 购物车.gif 开发计划 1、商品详情页将商品信息放入缓存2、购物车页面读取缓存获取商品信息3、购物车商品计算和删除缓存商品 一、商品详情页将商品信息放入缓存 detail.wxml <button>确定</button> 登录后复制 绑定bindtap事件将商品加入购物车。 detail.js /** * 加入购物车 */ addCar: function (e) { var goods = this.data.goods; goods.isSelect=false; var count = this.data.goods.count; var title = this.data.goods.title; if (title.length > 13) { goods.title = title.substring(0, 13) + '...'; } // 获取购物车的缓存数组(没有数据,则赋予一个空数组) var arr = wx.getStorageSync('cart') || []; console.log("arr,{}", arr); if (arr.length > 0) { // 遍历购物车数组 …