Using Axios is there a way to “hook” a function to every post request?
I have a ‘notification’ module in Vue.js
store, which stores API responses, so I need to call an updateResponse
method in every post request .then
Advertisement
Answer
Just use Axios interceptors
axios.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data return response; }, function (error) { // Any status codes that falls outside the range of 2xx cause this function to trigger // Do something with response error return Promise.reject(error); });