axios-miniprogram/src/defaults.ts

42 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2023-04-18 19:50:40 +08:00
import { getDefaultAdapter } from './adapter';
import { AxiosInstanceDefaults } from './axios';
2023-03-23 20:09:00 +08:00
const defaults: AxiosInstanceDefaults = {
2023-04-16 16:02:18 +08:00
// 适配器,在支持的平台中有值。
// 对于不支持平台而言,此值始终为 undefined需要您手动适配。
2023-04-18 19:50:40 +08:00
adapter: getDefaultAdapter(),
2023-04-16 16:02:18 +08:00
// 请求头
2023-03-23 20:09:00 +08:00
headers: {
2023-04-16 16:02:18 +08:00
// 通用请求头
2023-03-23 20:09:00 +08:00
common: {
Accept: 'application/json, text/plain, */*',
2023-03-23 20:09:00 +08:00
},
2023-04-16 16:02:18 +08:00
options: {}, // OPTIONS 方法请求头
get: {}, // GET 方法请求头
head: {}, // HEAD 方法请求头
post: {}, // POST 方法请求头
put: {}, // PUT 方法请求头
patch: {}, // PATCH 方法请求头
delete: {}, // DELETE 方法请求头
trace: {}, // TRACE 方法请求头
connect: {}, // CONNECT 方法请求头
2023-03-23 20:09:00 +08:00
},
2023-04-16 16:02:18 +08:00
// 校验状态码
2023-03-23 20:09:00 +08:00
validateStatus(status: number): boolean {
return status >= 200 && status < 300;
},
2023-04-16 16:02:18 +08:00
// 返回的数据格式
2023-03-23 20:09:00 +08:00
dataType: 'json',
2023-04-16 16:02:18 +08:00
// 响应的数据类型
2023-03-23 20:09:00 +08:00
responseType: 'text',
2023-04-16 16:02:18 +08:00
// 超时时长
timeout: 10000,
2023-03-23 20:09:00 +08:00
};
export default defaults;