美文网首页
JS 获取 URL参数

JS 获取 URL参数

作者: jesse28 | 来源:发表于2022-08-04 10:47 被阅读0次

    参考链接:https://www.runoob.com/w3cnote/js-get-url-param.html

    image.png
        getToken(variable) {
          let temp = window.location.hash.split("?")[1];
          // let neirong = temp.substring(temp.indexOf("=") + 1, temp.length); //获取token
          console.log("search内容", temp);
          var vars = temp.split("&");
          for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
              return pair[1];
            }
          }
          return false;
        },
    
        // 截取token
        getQueryVariable(variable) {
          const loading = this.$loading({
            lock: true,
            text: "拼命跳转中...",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
    
          let temp = window.location.hash.split("?")[1];
          // let neirong = temp.substring(temp.indexOf("=") + 1, temp.length); //获取token
         let neirong =  this.getToken('token')
          console.log("截取到的token", neirong);
          return
          this.$store
            .dispatch("user/login", neirong)
            .then((res) => {
              console.log("拿到的token", res);
              loading.close();
              // 成功之后跳转
              window.location.href = `${window.webConfig.jump}/case/#/?token=${res.data.data}&code=productCase`;
              // window.location.href="http://183.230.190.228:8002/case/#/?token=62ec71f7a774f936038cb834&code=productCase"
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
            });
        },
    
    image.png

    相关文章

      网友评论

          本文标题:JS 获取 URL参数

          本文链接:https://www.haomeiwen.com/subject/nqhpwrtx.html