美文网首页
AXIOS的一些配置

AXIOS的一些配置

作者: xiaoaiai | 来源:发表于2017-08-20 12:32 被阅读0次
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就可以了

相关文章

网友评论

      本文标题:AXIOS的一些配置

      本文链接:https://www.haomeiwen.com/subject/dlrfdxtx.html