axios 请求参数去空
const filterNullParams = (params, allValue) => {
Object.keys(params).filter(
key => (
params[key] === ''
|| params[key] === undefined
|| params[key] === null
)
&& delete params[key]
);
return params;
}
const queryList = () => {
const reqData = {
a: 1,
b: '',
c: -1,
}
axios.get('xxxxxxx', { params: filterNullParams(reqData) })
.then(res => res.data)
.then((res) => {
// 代码
});
}
转载自:https://segmentfault.com/a/1190000043182865