diff --git a/src/api/index.js b/src/api/index.js index e02e2169..29000ca5 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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 + } + }) }) } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 0fd59939..25253c98 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -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 }) {