微信小程序页面传参被截取问题

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

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

正常情况

 

// 传参页面
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
    })
  },

 

posted @ 2021-04-15 16:07  Samuel-Leung  阅读(653)  评论(0编辑  收藏  举报