import axios, {AxiosInstance, AxiosResponse, InternalAxiosRequestConfig} from "axios";
let baseurl = '/miniapis';
const myAxios:AxiosInstance=axios.create({
timeout: 10000,
withCredentials: true,
})
myAxios.interceptors.request.use((res:InternalAxiosRequestConfig):any=>{
res.headers['token']= window.localStorage.getItem('token')||''
return res
}, (error):object=> {
return Promise.reject(error);
});
myAxios.interceptors.response.use( (response:AxiosResponse):any =>{
const data = response.data;
console.log(response)
if (response.status != 200) {
return Promise.reject(data);
} else {
console.log('成功')
return Promise.resolve(data);
}
}, (error):any =>{
return Promise.reject(error);
});
export function get(url: string, params?: object){
return myAxios.get(baseurl+url,{
params,
})
}
export function post(url: string, data?: object){
return myAxios.post(baseurl+url,data)
}
export default myAxios