写在前面
- 此代码用于个人来查询,不做他用
- 可以实现对请求的精细化控制
- 全局可以实现拦截
- 创建的实例可以实现拦截
- 每个请求可以实现拦截
代码
类型
import type {
AxiosRequestConfig,
AxiosResponse,
InternalAxiosRequestConfig
} from 'axios'
export interface YMInterceptors {
successRequestFn?: (
config: InternalAxiosRequestConfig
) => InternalAxiosRequestConfig
failRequestFn?: (err: any) => any
successResponseFn?: (res: AxiosResponse) => AxiosResponse
failResponseFn?: (err: any) => any
}
export interface YMInstanceInterceptors<T = AxiosResponse> {
successRequestFn?: (config: AxiosRequestConfig) => AxiosRequestConfig
successResponseFn?: (res: T) => T
}
export interface YMAxiosRequestConfig<T>