index.d.ts
看起来是一个规范文件,约束了 axios 的所有 api,这里就看几个常规的
AxiosRequestConfig
export interface AxiosRequestConfig {
url?: string;
method?: Method;
baseURL?: string;
transformRequest?: AxiosTransformer | AxiosTransformer[];
transformResponse?: AxiosTransformer | AxiosTransformer[];
headers?: any;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
timeoutErrorMessage?: string;
withCredentials?: boolean;
adapter?: AxiosAdapter;
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
onDownloadProgress?: (progressEvent: any) => void;
maxContentLength?: number;
validateStatus?: (status: number) => boolean;
maxRedirects?: number;
socketPath?: string | null;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
}
这个就是 axios 的请求配置参数约束,常用的几个就是:
url:请求的路径method: 请求的方法(get、post、put,delete)headers:请求头(推荐不自定义)params:路径参数data:post参数responseType:响应数据类型onUploadProgress:上传进度cancelToken:取消传输token
AxiosResponse
这个是 Axios 响应对象的约束,可以清晰的看到它返回了一个标准的 http 相应对象:
data:响应数据status:状态码statusText:状态文本headers:响应头config:配置request:请求体
AxiosInstance
这个就是 axios 本 axios 了,约束了 axios 对象属性
提供了各种方法:
get:发送get请求post:发送post请求config:请求配置getUri:获取资源路径
AxiosError
这个是 axios 的错误对象
他有自带一个 toJSON 方法可以将错误对象转成 json
Last updated
Was this helpful?