收藏
回答

识别小程序码得路径和参数?

例如:有多个小程序码  码1:path = 123  码2: path=456

怎么样才能快速识别他们得参数和路径呢?

回答关注问题邀请回答
收藏

2 个回答

  • 睡前原谅一切
    睡前原谅一切
    2019-09-11

    getQueryString 可封装到 util下。下次直接调用 util.getQueryString[‘参数名’]

    //页面初始化加载

      onLoad(options) {

        if (!options.scene) { //判断不是从小程序码进来的
          this.setData({
            partJobId: options.partJobId ||  '',
          })
        } else {
          var getQueryString = {}
          var strs = decodeURIComponent(options.scene).split('&') //以&分割
          //取得全部并赋值
          for (var i = 0; i < strs.length; i++) {
            getQueryString[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
          }
          this.setData({
            partJobId: getQueryString['partJobId'] || ''
          })
        }
      },


    2019-09-11
    有用 2
    回复 7
    • "
      2019-09-11
      嘿!大神~
      2019-09-11
      回复
    • 睡前原谅一切
      睡前原谅一切
      2019-09-11回复
      嘿~,大哥有啥吩咐~
      2019-09-11
      回复
    • 扶苏。
      扶苏。
      2019-09-11
      啊~,有点没明白,这是把他解析了,然后存起来这?我想看到路径和参数咋看呢。
      2019-09-11
      回复
    • 睡前原谅一切
      睡前原谅一切
      2019-09-11回复扶苏。
      路径 打印 options.path.参数 打印options.scene
      2019-09-11
      回复
    • 睡前原谅一切
      睡前原谅一切
      2019-09-11
      options.scene针对通过接口b生成的小程序码
      2019-09-11
      回复
    查看更多(2)
  • Mr.Zhao
    Mr.Zhao
    2019-09-11
    function GetQueryString(name)
    {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null){
    return r[2];
    }
    return null;
    }


    2019-09-11
    有用 1
    回复
登录 后发表内容
问题标签