//一般会通过location.search拿到路由传递的参数,并进行反序列化得到对象
function parseUrlSearch() {
const search = '?age=25&name=TYJ'
return search.replace(/(^\?)|(&$)/g, "").split("&").reduce((t, v) = > {
const[key, val] = v.split("=");
t[key] = decodeURIComponent(val);
return t;
}, {});
}
console.log(parseUrlSearch()); // { age: "25", name: "TYJ" }
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8