vuvivian's blog

越努力,越幸运.

  1. 1. 静态菜单
  2. 2. 数据格式
  3. 3. 在template中生成有限级数的菜单(这里写了四级)
  4. 4. 在render函数中生成无限级数的菜单

静态菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<Menu theme="dark" width="auto">
<Submenu name="1">
<template slot="title">
<Icon type="ios-paper" />
内容管理
</template>
<Submenu name="2">
<template slot="title">
<Icon type="ios-paper" />
文章管理
</template>
<Submenu name="3">
<template slot="title">
<Icon type="ios-paper" />
文章管理
</template>
<MenuItem name="1-2">评论管理</MenuItem>
<Submenu name="4">
<template slot="title">
<Icon type="ios-paper" />
文章管理
</template>
<MenuItem name="1-2">评论管理</MenuItem>
<MenuItem name="1-3">举报管理</MenuItem>
</Submenu>
</Submenu>
<MenuItem name="1-3">举报管理</MenuItem>
</Submenu>
<MenuItem name="1-3">举报管理</MenuItem>
</Submenu>
</Menu>

数据格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
"id": "112123333",
"result": {
"menuData": [{
"title": "财务",
"id": "acc",
"order": 1,
"icon":"",
"translation":"",
"children":[]
},{
"title": "供应链",
"id": "gyl",
"order": 2,
"icon":"",
"translation":"",
"children":[{
"title": "采购",
"id": "cg",
"order": 1,
"icon":"",
"translation":"",
"children":[]
},{
"title": "销售",
"id": "xs",
"order": 2,
"icon":"",
"translation":"",
"children":[{
"title": "订单管理",
"id": "ddgl",
"order": 1,
"icon":"",
"translation":"",
"children":[{
"title": "销售订单",
"id": "xsdd",
"order": 1,
"icon":"",
"translation":"",
"children":[]
},{
"title": "合同管理",
"id": "htgl",
"order": 2,
"icon":"",
"translation":"",
"children":[{
"title": "销售合同",
"id": "xsht",
"order": 1,
"icon":"",
"translation":"",
"children":[]
}]
}]
}]
}]
}]
}
}

在template中生成有限级数的菜单(这里写了四级)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<Menu theme="dark" width="auto">
<template v-for="(item) in menuData" >
<!-- 第一级 -->
<Submenu v-if="item.children.length > 0" :key="item.id" :name="item.id">
<template slot="title">
<Icon :type="item.icon" />
{{item.title}}
</template>
<!-- 第二级 -->
<template v-for="(children) in item.children">
<Submenu v-if="children.children.length > 0" :name="children.id" :key="children.id">
<template slot="title">
<Icon :type="children.icon" />
{{children.title}}
</template>
<!-- 第三级 -->
<template v-for="(third) in children.children">
<Submenu v-if="third.children.length > 0" :name="third.id" :key="third.id">
<template slot="title">
<Icon :type="third.icon" />
{{third.title}}
</template>
<!-- 第四级 -->
<template v-for="(fourth) in third.children">
<MenuItem :name="fourth.id" :key="fourth.id">
<Icon :type="fourth.icon" />
{{fourth.title}}
</MenuItem>
</template>
</Submenu>
<MenuItem v-else :name="third.id" :key="third.id">
<Icon :type="third.icon" />
{{third.title}}
</MenuItem>
</template>
</Submenu>
<MenuItem v-else :name="children.id" :key="children.id">
<Icon :type="children.icon" />
{{children.title}}
</MenuItem>
</template>
</Submenu>
<MenuItem v-else :name="item.id" :key="item.id">
<Icon :type="item.icon" />
{{item.title}}
</MenuItem>
</template>
</Menu>

在render函数中生成无限级数的菜单

1
2


本文最后更新于 天前,文中所描述的信息可能已发生改变