From 616957799001d5b161ea8bb9cd0846e6255863f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Sun, 29 Dec 2019 14:24:11 +0800 Subject: [PATCH] fix: logout reset state --- src/store/modules/user.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index cbb75a0..100da14 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -2,13 +2,20 @@ import { login, logout, getInfo } from '@/api/user' import { getToken, setToken, removeToken } from '@/utils/auth' import { resetRouter } from '@/router' -const state = { - token: getToken(), - name: '', - avatar: '' +const getDefaultState = () => { + return { + token: getToken(), + name: '', + avatar: '' + } } +const state = getDefaultState() + const mutations = { + RESET_STATE: (state) => { + Object.assign(state, getDefaultState()) + }, SET_TOKEN: (state, token) => { state.token = token }, @@ -61,7 +68,7 @@ const actions = { logout({ commit, state }) { return new Promise((resolve, reject) => { logout(state.token).then(() => { - commit('SET_TOKEN', '') + commit('RESET_STATE', '') removeToken() resetRouter() resolve()