0
点赞
收藏
分享

微信扫一扫

STP环路避免实验(思科)

Go_Viola 03-22 21:00 阅读 2
一般分为两种网址截取方法:

第一种,例如链接:http://192.168.32.135:9020/#/authentication/Login?toekn=ceshi

 token 值出现在 URL 的 hash 部分,所以你需要使用 window.location.hash 来获取 hash 部分,然后使用 URLSearchParams 对象来解析 token 值。以下是示例代码

 //hash截取网址参数方法

    getQueryParam(paramName) {

      const url = window.location.hash.slice(1)

      const params = new URLSearchParams(url.split('?')[1])

      if (params != null) return params.get(paramName)

      return null

    },

//获取token值

let token = this.getQueryParam(token)

console.log(token)   //打印  ceshi

  第二种,例如链接:http://localhost:9021/spring/TiredOf/ceshi?token=ceshiToken

token 值出现在 URL 的查询参数部分。以下是示例代码:

//截取网址参数方法

    getQueryString(name) {

      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')

      var r = window.location.search.substr(1).match(reg)

      if (r != null) return unescape(r[2])

      return null

    }

//获取token值

let token = this.getQueryString(token)

console.log(token)   //打印  ceshiToken

举报

相关推荐

0 条评论