用正则去处理URL参数

1
2
3
4
5
6
7
8
// ?param=123&param1=456
getParam(name) {
let queryString = window.location.search.split('?')[1];
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
let result = queryString.match(reg);
//result:['param=123','','123','&']
return result ? decodeURIComponent(result[2]) : null
}