正常是有关uniapp跳转页面时正常传字符串是没问题的,但是,参数存在特殊字符时,就会导致参数无法传递。
这事就可以用到encodeURIComponent()和decodeURIComponent()
将字符串作为 URI 组件进行编码
encodeURIComponent()
具体代码
let data =JSON.stringify({
id:1,
name:'laowang',
age:22
})
uni.navigateTo({
url: '../test/index?data=' + encodeURIComponent(data)
})
:函数编码的 URI 进行解码
encodeURIComponent()
具体代码
onLoad(option) {
let data = JSON.parse(decodeURIComponent(option.data))
},
这样就可以传递特殊字符啦
本文介绍了在uniapp中遇到的页面跳转参数传递问题,特别是当参数包含特殊字符时。通过使用encodeURIComponent进行编码,然后在目标页面使用decodeURIComponent解码,可以成功传递包含特殊字符的数据。此方法适用于处理JSON对象并确保URL参数的正确传递。

658

被折叠的 条评论
为什么被折叠?



