From f2b1dfa403eb7b8c1689f36f932f7776662ddd33 Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Wed, 29 Dec 2021 04:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=E9=87=8C=20toLogin=20=E6=96=B9=E6=B3=95=EF=BC=8C=E5=85=88?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=86=8D=E8=B7=B3=E8=BD=AC=E7=99=BB=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 12 +++++++----- src/store/modules/user.js | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) 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 }) {