Skip to content

Commit 9481958

Browse files
committed
docs: add single file recursive menu demo
1 parent 4b24c13 commit 9481958

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

components/menu/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ exports[`renders ./components/menu/demo/switch-mode.md correctly 1`] = `
126126
</div>
127127
`;
128128
129+
exports[`renders ./components/menu/demo/template.md correctly 1`] = `
130+
<div style="width: 256px;"><button type="button" class="ant-btn ant-btn-primary" style="margin-bottom: 16px;"><i class="anticon anticon-menu-fold"></i></button>
131+
<ul class="ant-menu ant-menu-inline ant-menu-root ant-menu-dark" role="menu">
132+
<li role="menuitem" class="ant-menu-item ant-menu-item-selected" style="padding-left: 24px;"><i class="anticon anticon-pie-chart"></i> <span>Option 1</span></li>
133+
<li role="menuitem" class="ant-menu-submenu ant-menu-submenu-inline" menuinfo="[object Object]">
134+
<div aria-haspopup="true" class="ant-menu-submenu-title" style="padding-left: 24px;"><span><i class="anticon anticon-mail"></i><span>Navigation 2</span></span><i class="ant-menu-submenu-arrow"></i></div>
135+
<div></div>
136+
</li>
137+
</ul>
138+
</div>
139+
`;
140+
129141
exports[`renders ./components/menu/demo/theme.md correctly 1`] = `
130142
<div><label class="ant-checkbox-wrapper"><span class="ant-checkbox"><input type="checkbox" class="ant-checkbox-input" value=""><span class="ant-checkbox-inner"></span></span></label> Change Theme
131143
<br> <br>

components/menu/demo/SubMenu.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template functional>
2+
<a-sub-menu v-on="listeners" v-bind="data.attrs">
3+
<span slot="title"><a-icon type="mail" /><span>{{data.attrs.menuInfo.title}}</span></span>
4+
<template v-for="item in data.attrs.menuInfo.children">
5+
<a-menu-item v-if="!item.children" :key="item.key">
6+
<a-icon type="pie-chart" />
7+
<span>{{item.title}}</span>
8+
</a-menu-item>
9+
<sub-menu v-else :menuInfo="item" :key="item.key"/>
10+
</template>
11+
</a-sub-menu>
12+
</template>

components/menu/demo/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SiderCurrent from './sider-current'
55
import SwitchMode from './switch-mode'
66
import Theme from './theme'
77
import Vertical from './vertical'
8+
import Template from './template'
89
import CN from '../index.zh-CN.md'
910
import US from '../index.en-US.md'
1011
const md = {
@@ -35,6 +36,7 @@ export default {
3536
<SwitchMode />
3637
<Theme />
3738
<Vertical />
39+
<Template />
3840
<api>
3941
<CN slot='cn' />
4042
<US/>

components/menu/demo/template.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<cn>
2+
#### 单文件递归菜单
3+
使用单文件方式递归生成菜单。
4+
因组件内部会动态更改`a-sub-menu`的属性,如果拆分成单文件,无法将属性挂载到`a-sub-menu`上,你需要自行声明属性并挂载。为了实现方便,避免了属性的声明,本示例将其声明为函数式组件,并将所有属性挂载到`a-sub-menu`上。
5+
</cn>
6+
7+
<us>
8+
#### Single file recursive menu
9+
Use the single file method to recursively generate menus.
10+
The properties of `a-sub-menu` are dynamically changed inside the component. If you split the file into a single file and you cannot mount the `props` to `a-sub-menu`, you need to declare the `props` and mount it yourself. For the sake of convenience, the declaration of the `props` is avoided. This example declares it as a functional component and mounts all properties to `a-sub-menu`.
11+
</us>
12+
13+
```html
14+
<template>
15+
<div style="width: 256px">
16+
<a-button type="primary" @click="toggleCollapsed" style="margin-bottom: 16px">
17+
<a-icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" />
18+
</a-button>
19+
<a-menu
20+
:defaultSelectedKeys="['1']"
21+
:defaultOpenKeys="['sub1']"
22+
mode="inline"
23+
theme="dark"
24+
:inlineCollapsed="collapsed"
25+
>
26+
<template v-for="item in list">
27+
<a-menu-item v-if="!item.children" :key="item.key">
28+
<a-icon type="pie-chart" />
29+
<span>{{item.title}}</span>
30+
</a-menu-item>
31+
<sub-menu v-else :menuInfo="item" :key="item.key"/>
32+
</template>
33+
</a-menu>
34+
</div>
35+
</template>
36+
37+
<script>
38+
/* SubMenu.vue https://github.com/vueComponent/ant-design-vue/blob/master/components/menu/demo/SubMenu.vue */
39+
import SubMenu from './SubMenu'
40+
export default {
41+
components: {
42+
'sub-menu': SubMenu,
43+
},
44+
data () {
45+
return {
46+
collapsed: false,
47+
list: [
48+
{
49+
key: '1',
50+
title: 'Option 1',
51+
}, {
52+
key: '2',
53+
title: 'Navigation 2',
54+
children: [
55+
{
56+
key: '2.1',
57+
title: 'Navigation 3',
58+
children: [
59+
{ key: '2.1.1',
60+
title: 'Option 2.1.1',
61+
},
62+
],
63+
},
64+
],
65+
}],
66+
}
67+
},
68+
methods: {
69+
toggleCollapsed () {
70+
this.collapsed = !this.collapsed
71+
},
72+
},
73+
}
74+
</script>
75+
```

0 commit comments

Comments
 (0)