小程序页面跳转传递对象

背景:今天在做小程序页面跳转时,遇到一个需要传递对象的情况。在这里记录一下。
基本方法:先把对象转换成JSON格式,然后跳转之后又从JSON转换回来。
使用的函数:JSON.stringify():对象–>JSON
JSON.parse():JSON->对象
代码:
1.对象–>JSON

 jump2speify:function(e){
    var lookid=e.currentTarget.dataset.id;
    console.log(lookid );
    wx.navigateTo({
      url: '/pages/specify/specify?product=' + JSON.stringify(this.data.productList1[lookid]),
    })
  }

2.JSON->对象

onLoad: function (options) {
  var product=JSON.parse(options.product);
  console.log("good"+product.image);
 this.setData({
   product1:options.product,
   name:product.name,
   image:product.image,
   price:product.price,
   information:product.information,
 })
},

你可能感兴趣的:(小程序)