import axios from '../config/axiosConfig' import { AxiosRequestConfig, CustomSuccessData } from 'axios'; import { getValue } from '@/utils/common'; // 泛型接口 export interface Get { <T>(url: string, params?: object, config?: AxiosRequestConfig): Promise<CustomSuccessData<T>>; } axios.interceptors.response.use((response)=>{ return response; },(error)=>{ return error; }) const get: Get = async function (url: string,data?: object) { const res = await axios.get(url,{params:data}); return res.data; } const post: Get = async function (url: string,data?: object) { const res = await axios.post(url,data) return res.data; } function setToken(){ axios.defaults.headers.common['Authorization'] = "Bearer " + getValue("token"); } export { get, post, setToken }