最近在用 vue3+uni-app开发小程序;关于里面的一些方法分享一下
页面跳转传参,参数过长
在从页面跳转到详情等页面时,常常因为参数过长而无法传递完整
所以需要转码一下
encodeURIComponent(JSON.stringify(arr))//转码
JSON.parse(decodeURIComponent(arr))//解码
示例:从页面a到页面b
页面a
const gotoInfo = (e) => {
uni.navigateTo({
url: `/pages/newsInfo/newsInfo?id=${encodeURIComponent(JSON.stringify(e))}`
})
}
页面b
onLoad((e) => {
if (e.id) {
state.UUID = JSON.parse(decodeURIComponent(e.id))
}
})