File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -9,17 +9,20 @@ export default new Vuex.Store({
9
9
count : 0 ,
10
10
user : {
11
11
id : 'admin' ,
12
- log :'我是初始状态 , 请点击切换按钮'
12
+ log :'我是初始状态state.user.log , 请点击切换按钮'
13
13
} ,
14
+ log :'初始化我是初始状态state.log , 请点击切换按钮' ,
14
15
} ,
15
16
mutations : {
16
17
login ( state , action ) {
18
+ state . log = true ;
17
19
state . user = {
18
20
id :'admin' ,
19
21
log :true
20
22
} ;
21
23
} ,
22
24
logout ( state ) {
25
+ state . log = false ;
23
26
state . user = {
24
27
id :'admin' ,
25
28
log :false
Original file line number Diff line number Diff line change 4
4
<router-view ></router-view >
5
5
<div style =' border :2px solid ;margin :20px ;padding :20px ' >
6
6
<h3 >登陆状态:{{isLogin}}</h3 >
7
+ <h3 >登陆状态:{{isLogin2}}</h3 >
7
8
<button @click =" login" >切换状态</button >
8
9
</div >
9
10
20
21
},
21
22
computed: {
22
23
isLogin : function () {
24
+ return this .$store .state .log ;
25
+ },
26
+ isLogin2 : function () {
23
27
return this .$store .state .user .log ;
24
28
}
25
29
},
26
30
methods: {
27
31
login : function () {
28
- let state= this .$store .state .user . log ;
32
+ let state= this .$store .state .log ;
29
33
if (state){
30
34
this .$store .commit (' logout' );
31
35
}else {
You can’t perform that action at this time.
0 commit comments