axios的拦截请求与响应

比如发送请求显示loading,请求回来loading消失之类的
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import Loading from './components/Loading'
import stores from './store/store.js'
axios不能use哦


// 请求拦截(配置发送请求的信息)
axios.interceptors.request.use(function (config){
   // 处理请求之前的配置
   return config;
 }, function (error){
   // 请求失败的处理
   return Promise.reject(error);
 });


// 响应拦截(配置请求回来的信息)
axios.interceptors.response.use(function (response){
   // 处理响应数据
   return response;
 }, function (error){
   // 处理响应失败
   return Promise.reject(error);
 });
Vue.prototype.$http = axios  //其他页面在使用axios的时候直接  this.$http就可以了


原文:https://blog.csdn.net/qq_33207292/article/details/72867211 

猜你喜欢

转载自www.cnblogs.com/wr20190131/p/10494302.html