axios 发送请求时运行的函数(request)
//axios的一些配置,比如发送请求显示loading,请求回来loading消失之类的
//
axios.interceptors.request.use(function (config) { //配置发送请求的信息
stores.dispatch('showLoading')
return config;
}, function (error) {
return Promise.reject(error);
});
axios请求回来的时候运行的函数(response)
axios.interceptors.response.use(function (response) { //配置请求回来的信息
stores.dispatch('hideLoading')
return response;
}, function (error) {
return Promise.reject(error);
});
axios填坑(axios不能use)
Vue.prototype.$http = axios //其他页面在使用axios的时候直接 this.$http就可以了