- 在小程序端,我们是通过
JSON.stringify
和JSON.parse
来在页面之间传递对象数据的,我在开发中因为有些敏感数据采用了后端加密,前端解密再调用的方式,因为特殊字符"=",导致获取到这个"="号时,后面的数据都取不到了 - 通过查询资料分享找到了解决办法
decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码
encodeURIComponent() 函数把字符串作为 URI 组件进行编码。其中的某些字符将被十六进制的转义序列进行替换。
//页面传递时需要对该传递的对象编码,使用 encodeURIComponent()方法
wx.navigateTo({
url: '../test/test?paras=' + encodeURIComponent(JSON.stringify(this.data))
})
//接收对象时使用 decodeURIComponent()方法
onLoad: function(options) {
let paras = JSON.parse(decodeURIComponent(options.paras))
this.setData({
card: paras.card
})
},