-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kun
committed
Sep 2, 2019
1 parent
81926af
commit ac32a63
Showing
5 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export default function ({ route }) { | ||
console.log(111); | ||
export default function ({ route, store, redirect }) { | ||
// 如果用户不存在,跳到登录页面 | ||
if (!store.state.user.user) | ||
redirect('/user/login?redirect=' + route.path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export const actions = { | ||
nuxtServerInit({ commit }, { req }) { | ||
if (req.session.user) { | ||
commit("user/set", req.session.user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
export const state = () => { | ||
user: null | ||
}; | ||
|
||
export const mutations = { | ||
// 设置登录用户 | ||
set(state, user) { | ||
state.user = user; | ||
}, | ||
loginOut(state) { | ||
state.user = null; | ||
} | ||
} |