File tree Expand file tree Collapse file tree 4 files changed +25
-16
lines changed Expand file tree Collapse file tree 4 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 1
1
# lua-china
2
2
3
- > My brilliant Nuxt.js project
3
+ > Nuxt.js project 基于 node 14 版本
4
4
5
5
## Build Setup
6
6
Original file line number Diff line number Diff line change @@ -218,8 +218,20 @@ export default {
218
218
},
219
219
methods: {
220
220
updateUserInfo () {
221
+ this .user = { id: 0 }
221
222
let userInfo = localStorage .get (" user" );
222
- this .user = userInfo ? userInfo : { id: 0 };
223
+ if (userInfo) {
224
+ this .user = userInfo
225
+ } else {
226
+ apiService .get (" /userinfo" ).then (response => {
227
+ if (response .data .status === 4 ) {
228
+ return
229
+ }
230
+ if (response .data .data ) {
231
+ this .user = response .data .data
232
+ }
233
+ });
234
+ }
223
235
},
224
236
logout () {
225
237
localStorage .delete (" user" );
Original file line number Diff line number Diff line change @@ -190,9 +190,17 @@ export default {
190
190
if (this .user [k] == null ) delete this .user [k];
191
191
}
192
192
apiService .post (" /login" , this .user ).then (response => {
193
- let newAuth = response .data .data ;
194
- newAuth .login_at = Date .now ();
195
- localStorage .set (" user" , newAuth);
193
+ let responseBody = response .data
194
+ if (responseBody .status != 0 ) {
195
+ this .$toast ({
196
+ type: ' error' ,
197
+ message: responseBody .msg ,
198
+ });
199
+ return
200
+ }
201
+ let responseData = responseBody .data
202
+ responseData .login_at = Date .now ();
203
+ localStorage .set (" user" , responseData);
196
204
this .$toast ({
197
205
type: " success" ,
198
206
message: " 登录成功"
Original file line number Diff line number Diff line change @@ -10,17 +10,6 @@ const service = axios.create({
10
10
service . interceptors . response . use (
11
11
response => {
12
12
return new Promise ( resolve => {
13
- if ( response . data . status === 4 ) {
14
- window . location . href = '/login' ;
15
- return
16
- }
17
- if ( response . data . status !== 0 ) {
18
- Vue . toast ( {
19
- type : 'error' ,
20
- message : response . data . msg ,
21
- } ) ;
22
- return
23
- }
24
13
resolve ( response )
25
14
} ) ;
26
15
} ,
You can’t perform that action at this time.
0 commit comments