一、main.js设置axios拦截器

  1. yarn add axios
  1. Vue.prototype.axios = axios;
  2. axios.interceptors.request.use(function (config) {
  3. // Do something before request is sent
  4. store.state.isLoaing = true;
  5. return config;
  6. });
  7. axios.interceptors.response.use(function (response) {
  8. // Do something with response data
  9. store.state.isLoaing = false;
  10. return response;
  11. });

二、Vuex state属性中设置isLoading

  1. export default new Vuex.Store({
  2. state:{
  3. isLoaing:true
  4. }
  5. })

三、设置Loading

  1. <p v-if="this.$store.state.isLoaing">加载中</p>