新增页面
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user