修改vue项目中 src/utils/request.js中 service.interceptors.response.use内容
设置前
设置后
service.interceptors.response.use(
(response) => {
loadingInstance &&
setTimeout(function () {
loadingInstance.close()
}, 500)
const res = response.data
return res
},
(error) => {
loadingInstance &&
setTimeout(function () {
loadingInstance.close()
}, 500)
if (error && error.response) {
var { status, data } = error.response
if (status === 401 || status === 403) {
if (!loginInstance && whiteRoutes.indexOf(requestUrl) === -1) {
loginInstance = MessageBox.confirm('登录超时请重新登录', '重新登录', {
confirmButtonText: '好的',
type: 'warning'
})
.then(() => {
loginInstance = null
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
.catch(() => {
loginInstance = null
})
}
} else {
if (data) {
Message({
message: data,
type: 'error',
duration: 5 * 1000
})
} else {
Message({
message: data.message || '服务器异常,请稍后再试或联系管理员',
type: 'error',
duration: 5 * 1000
})
}
}
} else {
Message({
message: '服务器异常,请稍后再试或联系管理员',
type: 'error',
duration: 5 * 1000
})
}