一般都是由于转换JSON.stringify()的数据中转换符或者其他特殊字符,在JSON.parse()转换的时候回报错。
解决办法:
在JSON.stringify()转换前编码,JSON.parse()时再解码操作就可以解决了;
示例:
跳转传参
toTravelInfo(e) {
//encodeURIComponent转码
let type = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.type))
wx.navigateTo({
url: `xxxx?type=${type}`
})
},
接收数据
onLoad(options) {
//decodeURIComponent解码
let type = JSON.parse(decodeURIComponent(options.type))
}