zoukankan      html  css  js  c++  java
  • 微信小程序页面传参被截取问题

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

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

    正常情况

    // 传参页面
    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
        })
      },
  • 相关阅读:
    SpringMVC在使用Jackson2时关于日期类型格式化的问题
    Redis入门到高可用(八)——list
    LongAdder,AtomicIntegerFieldUpdater深入研究
    Redis入门到高可用(七)——Hash
    CAS缺点
    MySQL 当记录不存在时插入(insert if not exists)
    Redis入门到高可用(六)—— 字符串
    jsonp 跨域
    jvm
    指令重排序
  • 原文地址:https://www.cnblogs.com/Samuel-Leung/p/14662945.html
Copyright © 2011-2022 走看看