formatUrlQuery: function (...urlQuerys) {
let result = {};
urlQuerys.forEach((urlQuery) => {
if (typeof urlQuery == 'object') {
Object.assign(result, urlQuery);
} else {
Object.assign(result, sefa.parseUrlQuery(urlQuery));
}
});
const sdata = [];
for (let attr in result) {
sdata.push(`${attr}=${encodeURIComponent(result[attr])}`);
}
return sdata.join('&');
}
parseUrlQuery: function (url) {
url = url || '';
let obj = {};
let reg = /([^?=&]+)=([^?=&]+)/g;
url.replace(reg, function () {
obj[arguments[1]] = decodeURIComponent(arguments[2]);
});
return obj;
}
标签:function,sdata,URL,JS,url,let,urlQuery,互转,result From: https://www.cnblogs.com/msvc/p/17379759.html