微信小程序页面传参过长或者含有“?”

微信小程序页面传参过长或者含有“?”

微信小程序页面跳转的参数如果过长或者传的参数本身就含有‘?’标志的时候,会中断传的参数

正常情况

// 传参页面
const data = {
    questions: that.data.questions,
    questionImgUrl: that.data.questionImgUrl
  }
  wx.navigateTo({
    url: '../../pages/answer_questions/answer_questions?data=' + JSON.stringify(data)
  })
// 接受页面
  onLoad: function (options) {
    that = this
    const option = JSON.parse(options.data)
    that.setData({
      questions: option.questions,
      questionImgUrl: option.questionImgUrl
    })
  },

问题1:questions字段非常长,含有100道题的话,字符串长度超过限制,微信会做截取(大致在45KB的数据量左右会被截取)
问题2:questionImgUrl可能会含有‘?’,有时候后端为了压缩图片减少流量的时候,传的image一般都会含有‘?’,‘https://XXXXX/question.jpg?x-oss-process=image/format,webp’,微信也会做截取

处理之后:

// 传参页面
const data = {
    questions: that.data.questions,
    questionImgUrl: that.data.questionImgUrl
  }
  wx.navigateTo({
    url: '../../pages/answer_questions/answer_questions?data=' + encodeURIComponent(JSON.stringify(data))
  })
// 接受页面
  onLoad: function (options) {
    that = this
    const option = JSON.parse(decodeURIComponent(options.data))
    that.setData({
      questions: option.questions,
      questionImgUrl: option.questionImgUrl
    })
  },
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值