小程序地址传参有长度限制怎么处理

阅读 78

2022-03-25

小程序传参通过JSON.parse转换参数时报错信息如下:

SyntaxError: Unexpected end of JSON input     at JSON.parse (<anonymous>)

解决办法如下:
/**1.在准备传参跳转的页面**/
let competition = {}//这是一个很长的很多数据的对象
//转成String编码一下
competition = encodeURIComponent(JSON.stringify(competition))
wx.navigateTo({
     url:`pages/common/index?info=${competition}`
})
/**2.在接收参数的页面**/
onLoad(options){
    let info= decodeURIComponent(options.info)
    this.info= JSON.parse(info)
}

精彩评论(0)

0 0 举报