使用js截取路径参数方法
1.根据传入的路径和参数名称截取
export function getUrlParams(href,name) {
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(href)) {
return unescape(RegExp.$2.replace(/\+/g, " "))
};
return "";
}
2.获取路径中的指定参数名称
export function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
var context = "";
if (r != null)
context = r[2];
reg = null;
r = null;
return context == null || context == "" || context == "undefined" ? "" : context;
}