增加令牌自动续期功能

This commit is contained in:
pixel
2020-08-17 14:04:02 +08:00
parent 9679616935
commit 0239f7b97c
7 changed files with 62 additions and 55 deletions

View File

@@ -21,13 +21,13 @@ const showLoading = () => {
}
const closeLoading = () => {
acitveAxios--
if (acitveAxios <= 0) {
clearTimeout(timer)
loadingInstance && loadingInstance.close()
acitveAxios--
if (acitveAxios <= 0) {
clearTimeout(timer)
loadingInstance && loadingInstance.close()
}
}
}
//http request 拦截器
//http request 拦截器
service.interceptors.request.use(
config => {
showLoading()
@@ -37,7 +37,7 @@ service.interceptors.request.use(
config.headers = {
'Content-Type': 'application/json',
'x-token': token,
'x-user-id':user.ID
'x-user-id': user.ID
}
return config;
},
@@ -57,6 +57,9 @@ service.interceptors.request.use(
service.interceptors.response.use(
response => {
closeLoading()
if (response.headers["new-token"]) {
store.commit('user/setToken', response.headers["new-token"])
}
if (response.data.code == 0 || response.headers.success === "true") {
return response.data
} else {