页面1:
// 进入店铺简介页面 goShopIntroduce: function(){ var shopInfo = JSON.stringify(this.data.shopInfo); wx.navigateTo({ url: '/pages/shopIntroduce/shopIntroduce?shopInfo=' + shopInfo, }) },
页面2:
onLoad: function (options) { var shopInfo = JSON.parse(options.shopInfo) console.log(shopInfo); this.setData({ shopInfo: shopInfo }) },
如果传递的数据中包含特殊字符,需要编码解码
页面1:
var goodsInfo = encodeURIComponent(JSON.stringify(this.data.goodsInfo));//encodeURIComponent函数可把字符串作为URI组件传递
页面2:
// 先解码,再转成json
var goodsInfo1 = decodeURIComponent(options.goodsInfo);
var goodsInfo = JSON.parse(goodsInfo1);