UNPKG

ez-axios

Version:
117 lines (107 loc) 4.31 kB
import { AxiosResponse } from 'axios'; /** * @description ez-axios 更灵活的单项设置 */ export declare class AloneSet { /** * @description 设置全局基础地址 * @param baseURL */ static baseURL(baseURL: string): void; /** * @description 设置全局代理标记 * @param mark */ static mark(mark: string | Array<string>): void; /** * @description 设置全局请求超时时间 * @param timeout */ static timeout(timeout: number): void; /** * @description 设置全局简要数据结构 * @param briefly */ static briefly(briefly: boolean): void; /** * @description 设置全局加载动画 * @param loading */ static loading(loading: boolean): void; /** * @description 设置全局请求头 * @param headers */ static header(headers: Record<string, string>): void; /** * @description 设置全局错误处理 * @param error */ static error(error: (status: number) => void): void; /** * @description 设置全局请求拦截 * @param success */ static success(success: (response: AxiosResponse) => void): void; } /** * @description ez-axios 全局配置(建议只在项目入口文件调用一次) * @param options */ declare const _default: (options?: Partial<ezAxiosOptions>) => void; export default _default; /** * @description del 方法,对应 delete 请求 * @param { String } url 接口地址 * @param { Record<string, string> | Array } params [请求参数]:只能作为第二个参数 * @param { String } requestType [请求参数类型]:json(默认)、query * @param { ezAxiosOptions } customOptions [自定义设置]:不可作为前两个参数,会覆盖全局配置 * @returns delete 请求的 Promise 处理 */ export declare function del(url: string, ...theArgs: any[]): Promise<any>; export declare interface ezAxiosOptions { baseURL: string; mark: string | Array<string>; timeout: number; briefly: boolean; loading: boolean; headers: Record<string, string | undefined | null>; error: (status: number) => void; success: (response: AxiosResponse) => void; } /** * @description get 方法,对应 get 请求 * @param { String } url 接口地址 * @param { Record<string, string> | Array } params [请求参数]:只能作为第二个参数 * @param { String } responseType [返回值类型]:(多用于下载)blob * @param { ezAxiosOptions } customOptions [自定义设置]:不可作为前两个参数,会覆盖全局配置 * @returns get 请求的 Promise 处理 */ export declare function get(url: string, ...theArgs: any[]): Promise<any>; export declare class Loading { private static loadingDom; constructor(); static show(opacity?: number, zIndex?: number): void; static close(): void; } /** * @description post 方法,对应 post 请求 * @param { String } url 接口地址 * @param { Record<string, string> | Array | File } params [请求参数]:只能作为第二个参数 * @param { String } requestType [请求参数类型]:json(默认)、query、file、data * @param { String } responseType [返回值类型]:(多用于下载)blob,请参数类型为query时失效 * @param { ezAxiosOptions } customOptions [自定义设置]:不可作为前两个参数,会覆盖全局配置 * @returns post 请求的 Promise 处理 */ export declare function post(url: string, ...theArgs: any[]): Promise<any>; /** * @description put 方法,对应 put 请求 * @param { String } url 接口地址 * @param { Record<string, string> | Array | File } params [请求参数]:只能作为第二个参数 * @param { String } requestType [请求参数类型]:json(默认)、query、file、data * @param { String } responseType [返回值类型]:(多用于下载)blob,请参数类型为query时失效 * @param { ezAxiosOptions } customOptions [自定义设置]:不可作为前两个参数,会覆盖全局配置 * @returns put 请求的 Promise 处理 */ export declare function put(url: string, ...theArgs: any[]): Promise<any>; export { }