How to output a vue component in the interceptor of axios?

I wrote a loading component, and then configured axios to intercept requests and responses.
wants to appear loading,
on the request and make the loading component disappear. I don"t know how to write it.

clipboard.png

loading

clipboard.png

then remove loading after getting the request

Mar.02,2021
Register a loading state in

vuex, and change the loading state in the axios interceptor


Why do you have to output a component? You can control the v-show state of the loading component in different function hooks


/ / add request interceptor
axios.interceptors.request.use (function (config) {

// 
return config;

}, function (error) {

// 
return Promise.reject(error);

});

/ / add response interceptor
axios.interceptors.response.use (function (response) {

// 
return response;

}, function (error) {

// 
return Promise.reject(error);

});

Menu