import axios from 'axios'
// 引入axios以及element ui中的loading和message组件
import { MessageBox,Indicator } from 'mint-ui';
// 超时时间
axios.defaults.timeout = 5000
// http请求拦截器
var loadinginstace
axios.interceptors.request.use(config => {
if(config.url.indexOf("?")!=-1){
config.url = config.url + "&_v=" + genVersion();
}else{
config.url = config.url + "?_v=" + genVersion();
}
console.log(config.url);
Indicator.open({
//text: '加载中,请稍后...',
spinnerType: 'fading-circle'
});
return config
}, error => {
MessageBox.alert('数据加载超时,请检查您的网络或稍后重试!').then(action => {
Indicator.close();
});
return Promise.reject(error)
})
// http响应拦截器
axios.interceptors.response.use(data => {// 响应成功关闭loading
Indicator.close();
return data
}, error => {
MessageBox.alert('数据加载失败!').then(action => {
Indicator.close();
});
return Promise.reject(error)
})
export default axios;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)