牛骨文教育服务平台(让学习变的简单)
博文笔记

axios的拦截请求与响应

创建时间:2017-06-05 投稿人: 浏览次数:5608
比如发送请求显示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就可以了
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。