0
点赞
收藏
分享

微信扫一扫

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

女侠展昭 2022-03-25 阅读 78

小程序传参通过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 条评论