新增页面

This commit is contained in:
2026-09-09 22:34:32 +08:00
parent c9dce2c828
commit fe47a38a13
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export default {
},
methods: {
handleLogout() {
this.$store.commit("SET_TOKEN", '');
this.$store.commit("REMOVE_TOKEN", '');
this.$store.commit("SET_USERNAME", '');
this.$router.push("/login");
},
+6 -1
View File
@@ -5,13 +5,18 @@ Vue.use(Vuex)
const store = new Vuex.Store({
state: {
token: '',
token: localStorage.getItem('token') || '',
username: ''
},
mutations: {
// 设置token和用户名
SET_TOKEN(state, token) {
state.token = token;
localStorage.setItem('token', token);
},
REMOVE_TOKEN(state) {
state.token = '';
localStorage.removeItem('token');
},
SET_USERNAME(state, username) {
state.username = username;
+1 -1
View File
@@ -13,7 +13,7 @@ const request = axios.create({
request.interceptors.request.use(
(config) => {
// 在请求头中添加token
const token = store.state.token;
const token = localStorage.getItem('token');
if (token) {
config.headers['Authorization'] = `${token}`;
}