1.传递参数页
使用encodeURIComponent() 函数是为了解决字符串超出规定长度的问题
// 跳转函数
btnclick(e){
let obj={
11: {wait_date: "0天0小时0分23秒", get_date: "0天1小时34分21秒"},
12: {wait_date: "0天0小时0分37秒", get_date: "0天2小时30分12秒"},
20: {wait_date: "0天0小时0分14秒", get_date: "0天0小时2分43秒"}
}
//JSON.stringify() 方法用于将 值转换为 JSON 字符串
//encodeURIComponent() 函数可把字符串作为 URI 组件进行编码
let newObj=encodeURIComponent(JSON.stringify(obj))
wx.navigateTo({
url: `/pages/order/order-detail/detail/detail?newObj=${newObj}`
})
}
2.接收参数页
路径:pages/order/order-detail/detail/detail
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// JSON.parse()把JSON规则的字符串转换为JSON对象
//decodeURIComponent()对函数编码的URI 进行解码
console.log("接收到的数据",JSON.parse(decodeURIComponent(options.newObj)));
/**
* 打印的值
* {
* 11: {wait_date: "0天0小时0分23秒", get_date: "0天1小时34分21秒"},
12: {wait_date: "0天0小时0分37秒", get_date: "0天2小时30分12秒"},
20: {wait_date: "0天0小时0分14秒", get_date: "0天0小时2分43秒"},
}
*/
}