401状态拦截
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
import store from '@/stores'
|
||||
import router from '@/router'
|
||||
|
||||
/**
|
||||
* 自定义 JSON 解析:将超出安全整数范围的数字转为字符串,防止精度丢失
|
||||
@@ -39,9 +40,9 @@ service.interceptors.response.use(
|
||||
(error) => {
|
||||
const status = error.response?.status
|
||||
if (status === 401) {
|
||||
// 同步重置前端登录状态,弹出登录框
|
||||
// 同步重置前端登录状态,跳转登录页
|
||||
store.commit('SET_AUTHENTICATED', false)
|
||||
store.dispatch('openLogin', window.location.pathname)
|
||||
router.push({ name: 'Login', query: { redirect: window.location.pathname } })
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
} else {
|
||||
ElMessage.error(error.response?.data?.msg || '请求失败')
|
||||
|
||||
Reference in New Issue
Block a user