一、main.js设置拦截器
npm i axios -S
import axios from 'axios'Vue.prototype.axios = axios;//定义一个请求拦截器axios.interceptors.request.use(function(config){store.state.isShow=true; //在请求发出之前进行一些操作return config})//定义一个响应拦截器axios.interceptors.response.use(function(config){store.state.isShow=false;//在这里对返回的数据进行处理return config})
二、Vuex state状态设置控制loading的显隐
}export default new Vuex.Store({state: {isShow:true}})
三、设置Loading
//element-ui<div id="app" v-loading="this.$store.state.isShow"><router-view/></div>
