浏览器端post参数转get参数, 包括含有List的情况, 直接上代码:
function objToStr(obj) {
let paramArr = Object.keys(obj).reduce((acc, cur) => {
if (obj[cur] instanceof Array ) {
for (index in obj[cur]) {
acc.push(cur + '=' + obj[cur][index]);
}
} else {
acc.push(cur + '=' + obj[cur]);
}
return acc;
}, []);
return paramArr.join('&');
}
function strToObj(str) {
let strParam = window.location.search.substr(1);
let arr = strParam.split('&');
let obj={};
for(let item of arr){
let keyarr=item.split('=');
obj[keyarr[0]]=keyarr[1];
}
},