求助,一个前后端联调的问题
javascript
这是前端的一个调用后端接口的请求,
treeSelect().then((response) = {
console.log(response)
感觉像是拦截器之类的吃掉了 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}`);
}