厦门网站设计建设,建筑网片厂家货源平台,木藕设计网,廊坊seo网站管理一般分为两种网址截取方法#xff1a;
第一种#xff0c;例如链接#xff1a;http://192.168.32.135:9020/#/authentication/Login?toeknceshi token 值出现在 URL 的 hash 部分,所以你需要使用 window.location.hash 来获取 hash 部分#xff0c;然后使用 URLSearchPara…一般分为两种网址截取方法
第一种例如链接http://192.168.32.135:9020/#/authentication/Login?toeknceshi 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?tokenceshiToken
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