Skip to content

Commit

Permalink
token超时处理
Browse files Browse the repository at this point in the history
  • Loading branch information
daxiongYang committed Feb 11, 2018
1 parent b4e880a commit f22ef0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ service.interceptors.request.use(config => {
config.headers['token'] = Vue.cookie.get('token')
return config
}, error => {
Promise.reject(error)
return Promise.reject(error)
})

// response拦截器
service.interceptors.response.use(response => {
if (response.data && response.data.code === 401) { // 401, token失效
Vue.cookie.delete('token')
router.push({ name: 'login' })
}
return response
},
error => {
}, error => {
return Promise.reject(error)
})

Expand Down
3 changes: 2 additions & 1 deletion src/views/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@
API.user.info().then(({data}) => {
if (data && data.code === 0) {
this.loading = false
this.DELETE_CONTENT_TABS([])
this.UPDATE_USER_ID({ id: data.user.userId })
this.UPDATE_USER_NAME({ name: data.user.username })
}
})
},
...mapMutations(['UPDATE_DOCUMENT_CLIENT_HEIGHT', 'UPDATE_USER_ID', 'UPDATE_USER_NAME'])
...mapMutations(['UPDATE_DOCUMENT_CLIENT_HEIGHT', 'UPDATE_USER_ID', 'UPDATE_USER_NAME', 'DELETE_CONTENT_TABS'])
}
}
</script>

0 comments on commit f22ef0e

Please sign in to comment.