微信小程序刷新页面购物车数据消失解决方法

首先通过接口在onload里获取到购物车数据渲染出来
然后将购物车数据保存到本地


  wx.setStorageSync('cart', res.data.data[0].orderItemList)

然后在onShow里再拿出来

   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    
 var shoplist=wx.getStorageSync('cart')
 this.setData({
    
    
   shoplist:shoplist
 })
 this.prix()
  },

就可以了

猜你喜欢

转载自blog.csdn.net/wsxDream/article/details/112278876