一、main.js设置axios拦截器
yarn add axios
Vue.prototype.axios = axios;axios.interceptors.request.use(function (config) {// Do something before request is sentstore.state.isLoaing = true;return config;});axios.interceptors.response.use(function (response) {// Do something with response datastore.state.isLoaing = false;return response;});
二、Vuex state属性中设置isLoading
export default new Vuex.Store({state:{isLoaing:true}})
三、设置Loading
<p v-if="this.$store.state.isLoaing">加载中</p>
