📅  最后修改于: 2022-03-11 15:01:40.851000             🧑  作者: Mango
var numberOfAjaxCAllPending = 0;
// Add a request interceptor
axios.interceptors.request.use(function (config) {
numberOfAjaxCAllPending++;
// show loader
return config;
}, function (error) {
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
numberOfAjaxCAllPending--;
console.log("------------ Ajax pending", numberOfAjaxCAllPending);
if (numberOfAjaxCAllPending == 0) {
//hide loader
}
return response;
}, function (error) {
numberOfAjaxCAllPending--;
if (numberOfAjaxCAllPending == 0) {
//hide loader
}
return Promise.reject(error);
});