优化拦截器里 toLogin 方法,先清除用户信息状态再跳转登录页

This commit is contained in:
hooray 2021-12-29 04:37:49 +08:00
parent ac02f25e84
commit 65eff15674
2 changed files with 13 additions and 8 deletions

View File

@ -5,11 +5,13 @@ import store from '@/store/index'
import { ElMessage } from 'element-plus'
const toLogin = () => {
router.push({
name: 'login',
query: {
redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined
}
store.dispatch('user/logout').then(() => {
router.push({
name: 'login',
query: {
redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined
}
})
})
}

View File

@ -34,9 +34,12 @@ const actions = {
})
},
logout({ commit }) {
commit('removeUserData')
commit('menu/invalidRoutes', null, { root: true })
commit('menu/removeRoutes', null, { root: true })
return new Promise(resolve => {
commit('removeUserData')
commit('menu/invalidRoutes', null, { root: true })
commit('menu/removeRoutes', null, { root: true })
resolve()
})
},
// 获取我的权限
getPermissions({ state, commit }) {