mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-09 01:47:20 +08:00
32 lines
797 B
TypeScript
32 lines
797 B
TypeScript
import { AxiosRequestConfig } from "axios";
|
|
import { excludeProps } from "./utils";
|
|
/**
|
|
* 默认配置
|
|
*/
|
|
export const defaultConfig: AxiosRequestConfig = {
|
|
baseURL: "",
|
|
timeout: 10000, //10秒超时
|
|
headers: {
|
|
Accept: "application/json, text/plain, */*",
|
|
"Content-Type": "application/json",
|
|
"X-Requested-With": "XMLHttpRequest"
|
|
}
|
|
};
|
|
|
|
export function genConfig(config?: AxiosRequestConfig): AxiosRequestConfig {
|
|
if (!config) {
|
|
return defaultConfig;
|
|
}
|
|
|
|
const { headers } = config;
|
|
if (headers && typeof headers === "object") {
|
|
defaultConfig.headers = {
|
|
...defaultConfig.headers,
|
|
...headers
|
|
};
|
|
}
|
|
return { ...excludeProps(config!, "headers"), ...defaultConfig };
|
|
}
|
|
|
|
export const METHODS = ["post", "get", "put", "delete", "option", "patch"];
|