File tree Expand file tree Collapse file tree 6 files changed +72
-38
lines changed Expand file tree Collapse file tree 6 files changed +72
-38
lines changed Original file line number Diff line number Diff line change 4
4
.layout-main--side {
5
5
width : 200px ;
6
6
background-color : #051428 ;
7
+ user-select : none ;
8
+ cursor : pointer ;
7
9
.el-menu {
8
10
border-right : none ;
9
11
.el-menu-item {
16
18
}
17
19
</style >
18
20
19
- <template >
20
- <div class =" layout-main" flex =" dir:left" >
21
- <div class =" layout-main--side" flex-box =" 0" >
22
- <el-menu
23
- :default-active =" $route.path"
24
- background-color =" #051428"
25
- text-color =" #969CA5"
26
- active-text-color =" #FFF"
27
- router >
28
- <el-menu-item
29
- v-for =" menu of menus"
30
- :key =" menu.path"
31
- :index =" menu.path" >
32
- {{ menu.title }}
33
- </el-menu-item >
34
- </el-menu >
35
- </div >
36
- <div flex-box =" 1" >
37
- <router-view />
38
- </div >
39
- </div >
40
- </template >
41
-
42
21
<script >
43
22
import { menus } from ' @/router'
44
23
45
24
export default {
46
25
name: ' layout-main' ,
26
+ render () {
27
+ const createMenu = menu => menu .children ? createGroup (menu) : createItem (menu)
28
+ const createItem = menu => < el- menu- item index= { menu .path }> { menu .title }< / el- menu- item>
29
+ const createGroup = menu =>
30
+ < el- submenu index= { menu .path }>
31
+ < template slot= " title" > { menu .title }< / template>
32
+ { menu .children .map (child => createMenu (child)) }
33
+ < / el- submenu>
34
+ const node =
35
+ < div class = " layout-main" flex= " dir:left" >
36
+ < div class = " layout-main--side" flex- box= " 0" >
37
+ < el- menu
38
+ default- active= { this .$route .path }
39
+ background- color= " #051428"
40
+ text- color= " #969CA5"
41
+ active- text- color= " #FFF"
42
+ router>
43
+ { this .menus .map (menu => createMenu (menu)) }
44
+ < / el- menu>
45
+ < / div>
46
+ < div flex- box= " 1" >
47
+ < router- view/ >
48
+ < / div>
49
+ < / div>
50
+ return node
51
+ },
47
52
data () {
48
53
return {
49
54
menus
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <route-meta >
2
+ {
3
+ "title": "DEMO FOLDER 1"
4
+ }
5
+ </route-meta >
6
+
7
+ <template >
8
+ <router-view />
9
+ </template >
Original file line number Diff line number Diff line change
1
+ <route-meta >
2
+ {
3
+ "title": "DEMO 1-1"
4
+ }
5
+ </route-meta >
6
+
7
+ <template >
8
+ <div >
9
+ {{ $route.name }}
10
+ </div >
11
+ </template >
Original file line number Diff line number Diff line change
1
+ <route-meta >
2
+ {
3
+ "title": "DEMO 1-2"
4
+ }
5
+ </route-meta >
6
+
7
+ <template >
8
+ <div >
9
+ {{ $route.name }}
10
+ </div >
11
+ </template >
Original file line number Diff line number Diff line change @@ -2,13 +2,25 @@ import Vue from 'vue'
2
2
import Router from 'vue-router'
3
3
import routes from 'vue-auto-routing'
4
4
import { createRouterLayout } from 'vue-router-layout'
5
+ import { concat } from 'lodash'
5
6
6
7
Vue . use ( Router )
7
8
8
9
const RouterLayout = createRouterLayout ( layout => {
9
10
return import ( '@/layouts/' + layout + '.vue' )
10
11
} )
11
12
13
+ function routes2menus ( routes , parentPaths = [ ] ) {
14
+ return routes . map ( route => {
15
+ const menu = { }
16
+ const newParentPaths = concat ( parentPaths , route . path )
17
+ menu . path = newParentPaths . join ( '/' )
18
+ menu . title = route . meta . title
19
+ if ( route . children ) menu . children = routes2menus ( route . children , newParentPaths )
20
+ return menu
21
+ } )
22
+ }
23
+
12
24
export const router = new Router ( {
13
25
routes : [
14
26
{
@@ -19,7 +31,4 @@ export const router = new Router({
19
31
]
20
32
} )
21
33
22
- export const menus = routes . map ( route => ( {
23
- path : route . path ,
24
- title : route . meta . title
25
- } ) )
34
+ export const menus = routes2menus ( routes )
You can’t perform that action at this time.
0 commit comments