File tree 5 files changed +72
-28
lines changed 5 files changed +72
-28
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div class =" header" >
3
+ <div class =" collapse-btn" @click =" collapseChage" >
4
+ <i class =" el-icon-menu" ></i >
5
+ </div >
3
6
<div class =" logo" >后台管理系统</div >
4
7
<div class =" user-info" >
5
8
<el-dropdown trigger =" click" @command =" handleCommand" >
15
18
</div >
16
19
</template >
17
20
<script >
21
+ import bus from ' ../common/bus' ;
18
22
export default {
19
23
data () {
20
24
return {
25
+ collapse: false ,
21
26
name: ' linxin'
22
27
}
23
28
},
33
38
localStorage .removeItem (' ms_username' )
34
39
this .$router .push (' /login' );
35
40
}
41
+ },
42
+ collapseChage (){
43
+ this .collapse = ! this .collapse ;
44
+ bus .$emit (' collapse' , this .collapse );
36
45
}
37
46
}
38
47
}
47
56
line-height : 70px ;
48
57
color : #fff ;
49
58
}
59
+ .collapse-btn {
60
+ float : left ;
61
+ padding : 0 21px ;
62
+ cursor : pointer ;
63
+ }
64
+ .collapse-btn :hover {
65
+ background : rgb (40 ,52 ,70 );
66
+ }
50
67
.header .logo {
51
68
float : left ;
52
69
width :250px ;
53
- text-align : center ;
70
+ /* text-align: center; */
54
71
}
55
72
.user-info {
56
73
float : right ;
Original file line number Diff line number Diff line change 1
- <template >
2
- <div class =" wrapper" >
3
- <v-head ></v-head >
4
- <v-sidebar ></v-sidebar >
5
- <div class =" content" >
6
- <transition name =" move" mode =" out-in" ><router-view ></router-view ></transition >
7
- </div >
8
- </div >
9
- </template >
10
-
11
- <script >
12
- import vHead from ' ./Header.vue' ;
13
- import vSidebar from ' ./Sidebar.vue' ;
14
- export default {
15
- components: {
16
- vHead, vSidebar
17
- }
18
- }
19
- </script >
1
+ <template >
2
+ <div class =" wrapper" >
3
+ <v-head ></v-head >
4
+ <v-sidebar ></v-sidebar >
5
+ <div class =" content" :class =" {'content-collapse':collapse}" >
6
+ <transition name =" move" mode =" out-in" ><router-view ></router-view ></transition >
7
+ </div >
8
+ </div >
9
+ </template >
10
+
11
+ <script >
12
+ import vHead from ' ./Header.vue' ;
13
+ import vSidebar from ' ./Sidebar.vue' ;
14
+ import bus from ' ../common/bus' ;
15
+ export default {
16
+ data (){
17
+ return {
18
+ collapse: false
19
+ }
20
+ },
21
+ components: {
22
+ vHead, vSidebar
23
+ },
24
+ created (){
25
+ bus .$on (' collapse' , msg => {
26
+ this .collapse = msg;
27
+ })
28
+ }
29
+ }
30
+ </script >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div class =" sidebar" >
3
- <el-menu :default-active =" onRoutes" class = " el-menu-vertical-demo " background-color =" #324157"
3
+ <el-menu class = " sidebar-el-menu " :default-active =" onRoutes" :collapse = " collapse " background-color =" #324157"
4
4
text-color =" #bfcbd9" active-text-color =" #20a0ff" unique-opened router >
5
5
<template v-for =" item in items " >
6
6
<template v-if =" item .subs " >
7
7
<el-submenu :index =" item.index" :key =" item.index" >
8
8
<template slot="title">
9
- <i :class =" item.icon" ></i >{{ item.title }}
9
+ <i :class =" item.icon" ></i >< span slot = " title " > {{ item.title }}</ span >
10
10
</template >
11
11
<el-menu-item v-for =" (subItem,i) in item.subs" :key =" i" :index =" subItem.index" >
12
12
{{ subItem.title }}
15
15
</template >
16
16
<template v-else >
17
17
<el-menu-item :index =" item.index" :key =" item.index" >
18
- <i :class =" item.icon" ></i >{{ item.title }}
18
+ <i :class =" item.icon" ></i >< span slot = " title " > {{ item.title }}</ span >
19
19
</el-menu-item >
20
20
</template >
21
21
</template >
24
24
</template >
25
25
26
26
<script >
27
+ import bus from ' ../common/bus' ;
27
28
export default {
28
29
data () {
29
30
return {
31
+ collapse: false ,
30
32
items: [
31
33
{
32
34
icon: ' el-icon-setting' ,
93
95
onRoutes (){
94
96
return this .$route .path .replace (' /' ,' ' );
95
97
}
98
+ },
99
+ created (){
100
+ bus .$on (' collapse' , msg => {
101
+ this .collapse = msg;
102
+ })
96
103
}
97
104
}
98
105
</script >
101
108
.sidebar {
102
109
display : block ;
103
110
position : absolute ;
104
- width : 250px ;
105
111
left : 0 ;
106
112
top : 70px ;
107
113
bottom :0 ;
108
- background : #2E363F ;
114
+ }
115
+ .sidebar-el-menu :not (.el-menu--collapse ){
116
+ width : 250px ;
109
117
}
110
118
.sidebar > ul {
111
119
height :100% ;
112
120
}
113
- .sidebar i {
114
- margin-top : -4px ;
115
- }
116
121
</style >
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue' ;
2
+
3
+ // 使用 Event Bus
4
+ const bus = new Vue ( ) ;
5
+
6
+ export default bus ;
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ a{text-decoration: none}
19
19
padding : 40px ;
20
20
box-sizing : border-box;
21
21
overflow-y : scroll;
22
+ -webkit-transition : left .3s ease-in-out;
23
+ transition : left .3s ease-in-out;
24
+ }
25
+ .content-collapse {
26
+ left : 65px ;
22
27
}
23
28
.container {
24
29
padding : 30px ;
You can’t perform that action at this time.
0 commit comments