删除vuex中的username
This commit is contained in:
@@ -314,7 +314,7 @@ export default {
|
||||
// 关闭websocket连接,清除 token 和用户信息
|
||||
closeWebSocket();
|
||||
this.$store.commit("SET_TOKEN", "");
|
||||
this.$store.commit("SET_USERNAME", "");
|
||||
this.$router.push("/login");
|
||||
},
|
||||
|
||||
// 获取当前登录用户信息
|
||||
|
||||
@@ -57,7 +57,6 @@ export default {
|
||||
.then((response) => {
|
||||
const token = response.data.token;
|
||||
this.$store.commit("SET_TOKEN", token);
|
||||
this.$store.commit("SET_USERNAME", this.username);
|
||||
this.$router.push("/chat");
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
+1
-5
@@ -5,8 +5,7 @@ Vue.use(Vuex)
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
token: localStorage.getItem('token') || '',
|
||||
username: ''
|
||||
token: localStorage.getItem('token') || ''
|
||||
},
|
||||
mutations: {
|
||||
// 设置token和用户名
|
||||
@@ -17,9 +16,6 @@ const store = new Vuex.Store({
|
||||
REMOVE_TOKEN(state) {
|
||||
state.token = '';
|
||||
localStorage.removeItem('token');
|
||||
},
|
||||
SET_USERNAME(state, username) {
|
||||
state.username = username;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -53,7 +53,6 @@ request.interceptors.response.use(
|
||||
if (error.response && error.response.status === 401) {
|
||||
// 如果返回401,说明token过期或无效,清除token并跳转到登录页
|
||||
store.commit('SET_TOKEN', '');
|
||||
store.commit('SET_USERNAME', '');
|
||||
redirectToLogin();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
|
||||
Reference in New Issue
Block a user