代码如下:
let url = window.location.href;
// let url = 'http://xxx?token=123';
let token = this.getUrlParam(url,"token")
console.log('token:',token) //123
封装 getUrlParam
getUrlParam(url,key){
const regExp = new RegExp(key + '=([^&#]*)');
const index = url.indexOf('?');
let search = index !== -1 ? url.substring(index + 1) : '';
const results = regExp.exec(search);
if (results) {
return decodeURIComponent(results[1]);
} else {
return null;
}
},