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