准确获取URL地址参数

http://localhost:8080/?state=app&code=021axrkH0Il7Df2bEQkH0DMjkH0axrkP

准确获取code的值

getQueryString(name) {
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
getQueryString('code')//021axrkH0Il7Df2bEQkH0DMjkH0axrkP
getQueryString('state')//app
上一篇:vue+webpack+vue-cli获取URL地址参数


下一篇:POJ 1724 Roads