axios.js
775 字节
/**
* @file Axios 全局配置
*/
import axios from 'axios'
import { ENV } from '../constants/index'
const myAxios = axios.create({
baseURL: ENV.HOSTNAME,
// withCredentials: true
})
myAxios.defaults.timeout = 10000;
myAxios.interceptors.response.use((res) => {
if (res.status >= 200 && res.status < 300) {
return res;
}
return Promise.reject(res);
}, (error) => {
// 网络异常
if (axios.isCancel(error)) {
var err = { message: '路由切换,网络请求已取消', err: error, type: 'cancel' };
console.log(err);
return Promise.reject(err);
} else {
var err = { message: '网络异常,请刷新重试', err: error, type: 'responseError' };
console.log(err);
return Promise.reject(err);
}
});
export default myAxios