1.方法1-正则
getUrlKey(name) {
//构造一个含有目标参数的正则表达式对象**
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
let r =
window.location.search.substr(1).match(reg) ||
window.location.hash
.substring(window.location.hash.search(/\?/) + 1)
.match(reg);
if (r !== null) {
return decodeURIComponent(r[2]);//参数解码
}
},
2.方法2
getParams(name) {
//获取Url 参数
var GET = {};
var canshu = window.location.hash.split("?")[1] == undefined ? '' : window.location.hash.split("?")[1];
if (canshu != '') {
var strarr = canshu.split("&");
for (let i = 0; i < strarr.length; i++) {
var xx = strarr[i];
var mykey = xx.split('=')[0];
var myvalue = xx.split('=')[1];
GET[mykey] = myvalue;
}
}
return decodeURIComponent(GET[name]);//参数解码
},