JS 获取 URL参数

2022-08-04  本文已影响0人  jesse28

参考链接: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
上一篇 下一篇

猜你喜欢

热点阅读