对 qs stringify 重写

This commit is contained in:
sin 2019-03-06 21:57:53 +08:00
parent 1ebc7492fa
commit d51fc7f5d0

View File

@ -0,0 +1,37 @@
/* eslint-disable */
import qs from 'qs';
/**
* 过滤字符串为 '' 直接不传了
*
* @param params
*/
function filterEmptyStr(params) {
function filterObject(object) {
const res = {};
for (const key in params) {
const val = params[key];
if (typeof val === 'string' && val) {
res[key] = val;
} else {
res[key] = val;
}
}
return res;
}
if (typeof params === 'object') {
return filterObject(params);
} else if (params instanceof Array) {
let res = [];
for (const object in params) {
res.push(filterObject(params));
}
}
}
export function stringify(params) {
return qs.stringify(filterEmptyStr(params));
}
export default qs;