微信小程序页面传递数据

1.传递数组或者字典
记得要渲染:

   this.setData({
        height:height,
       cartList:this.data.cartList
       
      })

(1)A跳转到B之前使用wx.setStorageSync(‘info’, this.data.info);这个方法,将数据缓存到本地中。
(2)在B页面的onLoad()方法里,通过使用var data = wx.getStorageSync(‘info’)来获取到数据,然后可以通过setData的方法设置到Page的data数据里。
示例:将父页面的cartlist传到子页面

  • 父页面
 // 提交订单
  gotoOrder: function () {
     wx.setStorageSync('cartList', this.data.cartList);
      wx.navigateTo({
          url: '../order/order'
      })
  },
  • 子页面
 onLoad: function (options) {
  
    var width=wx.getSystemInfoSync().windowWidth
    var height=wx.getSystemInfoSync().windowHeight
    height=height-53-300;
    this.setData({
      height:height,
   
     
    }),
   **this.data.cartList = wx.getStorageSync('cartList')**
   console.log(this.data.cartList)
  },

版权声明:本文为kthvsxh原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。