likes
comments
collection
share

axios 请求参数去空

作者站长头像
站长
· 阅读数 10
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) => {
        // 代码
      });
  }