乐趣区

关于前端: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) => {// 代码});
  }
退出移动版