Skip to content

Instantly share code, notes, and snippets.

@AleksejDix
Forked from nemanja947/NprogressAxios.js
Created July 3, 2019 09:10
Show Gist options
  • Save AleksejDix/52e7eab445c18d33e659945bc8c19f96 to your computer and use it in GitHub Desktop.
Save AleksejDix/52e7eab445c18d33e659945bc8c19f96 to your computer and use it in GitHub Desktop.
NProgress implementation with Axios
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
NProgress.start();
return config;
}, function (error) {
// Do something with request error
console.error(error)
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Do something with response data
NProgress.done();
return response;
}, function (error) {
// Do something with response error
console.error(error)
return Promise.reject(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment