-
Notifications
You must be signed in to change notification settings - Fork 0
axios call api
PhamLinh0889 edited this page Sep 4, 2018
·
5 revisions
import axios from 'axios'
import router from '../router'
let axiosInstance = axios.create({
baseURL: 'http://api.dingo.lc',
timeout: 120000
})
const token = localStorage.getItem('user-token')
if (token) {
axios.defaults.headers.common['Authorization'] = token
}
axiosInstance.interceptors.request.use(function (config) {
console.log('axios interceptor before request-LinhPV')
return config
}, function (error) {
console.log('error in request-LinhPV')
return Promise.reject(error)
})
// Add a response interceptor
axiosInstance.interceptors.response.use((response) => {
console.log('axios interceptor response-LinhPV')
return response
}, (error) => {
if (error.response.status === 401) {
this.$store.dispatch(AUTH_LOGOUT)
return router.push({
path: '/login'
})
}
return Promise.reject(error)
})
export default axiosInstance
- add header authen