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
        })
      },
  • 相关阅读:
    Java实现 LeetCode 715 Range 模块(选范围)
    HTML 图像
    HTML 样式- CSS
    HTML <head>
    HTML 链接
    HTML 文本格式化
    目标检测中的anchor-based 和anchor free
    目标检测coco数据集点滴介绍
    Camera HDR Algorithms
    噪声标签的负训练:ICCV2019论文解析
  • 原文地址:https://www.cnblogs.com/Samuel-Leung/p/14662945.html
Copyright © 2011-2022 走看看