·
Across the Great Wall, we can reach every corner in the world.

感觉像是拦截器之类的吃掉了 response,把拦截器部分代码注释掉看看,或者在里面打日志。感觉你写的太复杂了,axios 可以在全局入口设置,代码里面直接 import axios 就可以用了:

import axios from 'axios';
import reject from '../errors/handler';

export function setUpAxios(signInPath: string, authPath: string) {
  if (process.env.NODE_ENV === 'development') {
    axios.defaults.baseURL = 'http://localhost:3000';
  } else {
    axios.defaults.baseURL = 'https://api.hackertalk.net';
  }
  axios.defaults.withCredentials = true;
  axios.interceptors.response.use(response => response, reject(signInPath, authPath));
}

封装:

import axios from 'axios';

export function getById(id: string) {
  return axios.get<Post>(`/v1/posts/${id}`);
}
Replies
1

解决了,是前端响应拦截器要求数据都要用统一的类型,我看 menuOptions 是数组,就用了集合,没有封装到统一的结果集里去,所以响应拦截不到 joy