axios request interceptor config code example
Example 1: axios post
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Example 2: axios.interceptors.response.use
HTTP.interceptors.response.use(function (response) {
return response
}, function(error) {
if (error.response.status === 401) {
store.dispatch('logout')
router.push('/login')
}
return Promise.reject(error.response.data)
})