import axios , { AxiosResponse , AxiosRequestConfig } from 'axios' ; export const baseUrl = 'http://localhost:3000/' ; axios . defaults . baseURL = baseUrl ; axios . defaults . headers . post [ 'Content-Type' ] = 'application/json' ; const handleError = ( error ) => { } ; const axiosInstance = axios . create ( { baseURL : baseUrl , } ) ; axiosInstance . interceptors . response . use ( res => res . data , err => { console . log ( err , '网络错误' ) ; } ) ; export { axiosInstance } ; const request = ( { url , data , method = 'post' , ... rest } ) => { return axios ( { url , data , method , ... rest , } ) . then ( function ( response ) { return response ; } ) . then ( function ( response ) { if ( response . status === 200 ) { return response . data ; } } ) . catch ( function ( error ) { handleError ( error . response ) ; } ) . finally ( function ( ) { } ) ; } ; export default request ;