删除vuex中的username

This commit is contained in:
2026-09-30 15:11:17 +08:00
parent 5de8de007b
commit 0ce763cc79
4 changed files with 2 additions and 8 deletions
+1 -1
View File
@@ -314,7 +314,7 @@ export default {
// 关闭websocket连接,清除 token 和用户信息
closeWebSocket();
this.$store.commit("SET_TOKEN", "");
this.$store.commit("SET_USERNAME", "");
this.$router.push("/login");
},
// 获取当前登录用户信息
-1
View File
@@ -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
View File
@@ -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;
}
}
})
-1
View File
@@ -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);