0👍
First. You can exploit the config
object that is accessible in both request and response interceptors:
axios.interceptors.request.use((config) => {
// Create a promise to pass to asyncBlock
config.loadingScreenPromise = new Promise((resolve, reject) => {
config.resolveLoadingScreenPromise = resolve;
config.rejectLoadingScreenPromise = reject;
});
this.$awn.asyncBlock(config.loadingScreenPromise, //... other params)
return config;
}, (error) => axios_error(error));
axios.interceptors.response.use((response) => {
// resolve loading screen promise
response.config.resolveLoadingScreenPromise()
return response.data;
}, (error) => {
// reject loading screen promise
error.config.rejectLoadingScreenPromise(error)
axios_error(error)
});
Second. Either call this.$awn.alert()
directly from error interceptor lambda function(to access Vue component’s this
) or pass this.$awn
to axios_error
function explicitly.
- [Vuejs]-Handle errors with parallel async requests
- [Vuejs]-Vue JS Encoding is changed in child components
Source:stackexchange.com