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


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

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

    正常情况

    // 传参页面
    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
        })
      },
  • 相关阅读:
    PHP register_shutdown_function函数详解
    Git
    JS动态加载JS与CSS文件
    解析PHP中ob_start()函数的用法
    PHP Fuzzing行动——源码审计 黑客注入防范
    PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载
    canvas 创建渐变图形
    视频作为背景的表单
    H5 pattern
    ajax函数里不能用this调用
  • 原文地址:https://www.cnblogs.com/Samuel-Leung/p/14662945.html
Copyright © 2020-2023  润新知