interceptors.response axios code example
Example 1: axios.interceptors.response.use
// Add a response interceptor
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)
})
Example 2: include axios
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>