How to use element ui's loading in axio.js 's interceptor to make all requests have the effect of loading

how to use element ui"s loading in axio.js "s interceptor, so that all requests have the effect of loading

Mar.28,2021

introduce element ui in the code file intercepted by axios
in the request interception of axios, full-screen load.
in the response interception of aixos, turn off loading.

//element-uiVue
//
const LOADING = {
  lock: true,
  spinner: 'el-icon-loading',
  background: 'rgba(0, 0, 0, 0.7)'
};
let loading;
//
axios.interceptors.request.use(config => {
  loading = Vue.$loading(LOADING);
  return config
}, error => {
  loading.close();
  return Promise.reject(error)
})
//
axios.interceptors.response.use(data => {
  loading.close();
  return Promise.resolve(data);
}, error => {
  loading.close();
  return Promise.reject(error)
})

register this component globally, import this component in app.vue, Vue.use (). When you go to the place where you request to set state, there is usually vuex to vuex directly to do, set two action methods. To manipulate the display of loading

Menu