import axios, {AxiosInstance, AxiosRequestConfig} from "axios"; type TAxiosOption = { baseURL: string; timeout: number; } // const config = { // baseURL: '/', // timeout: 120000 // } class Http { service: AxiosInstance; constructor(config:TAxiosOption) { this.service = axios.create(config); this.service.defaults.withCredentials = true this.service.interceptors.request.use( (value)=>{ if (value.headers !== null){ // @ts-ignore value.headers.Authorization = "Bearer "+localStorage.getItem("xxqg_token") } return value },()=>{ }) } get(url: string, params?: object, _object = {}): Promise> { return this.service.get(url, { params, ..._object }) } post(url: string, data?: object, _object:AxiosRequestConfig = {}): Promise> { return this.service.post(url, data, _object) } put(url: string, params?: object, _object = {}): Promise> { return this.service.put(url, params, _object) } delete(url: string, params?: any, _object = {}): Promise> { return this.service.delete(url, { params, ..._object }) } } export default Http export interface IResponseData { success: boolean; message?:string; data:T; code: string; error?:string }