naive-ui/demo/documentation/components/menu/enUS/horizontal.demo.md

115 lines
2.1 KiB
Markdown
Raw Normal View History

2020-02-07 22:31:26 +08:00
# Horizontal
A horiziontal menu.
```html
<n-menu
v-model="activeName"
mode="horizontal"
:items="menuItems"
/>
2020-02-07 22:31:26 +08:00
```
2020-10-22 17:25:26 +08:00
```html
<n-menu
v-model:value="activeKey"
mode="horizontal"
:items="menuItems"
/>
```
2020-02-07 22:31:26 +08:00
```js
2020-10-22 17:25:26 +08:00
import { h, resolveComponent } from 'vue'
2020-02-07 22:31:26 +08:00
import bookIcon from 'naive-ui/lib/icons/book-outline'
import personIcon from 'naive-ui/lib/icons/person-outline'
import wineIcon from 'naive-ui/lib/icons/wine-outline'
2020-10-22 17:25:26 +08:00
function renderIcon(icon) {
return () => h(resolveComponent('n-icon'), null, { default: () => h(icon) })
}
const menuItems = [
{
title: 'Hear the Wind Sing',
2020-10-22 17:25:26 +08:00
key: 'hear-the-wind-sing',
icon: renderIcon(bookIcon)
},
{
2020-10-22 17:25:26 +08:00
title: 'Pinball 1973',
key: 'pinball-1973',
icon: renderIcon(bookIcon),
disabled: true,
children: [
{
title: 'Rat',
2020-10-22 17:25:26 +08:00
key: 'rat'
}
]
},
{
title: 'A Wild Sheep Chase',
2020-10-22 17:25:26 +08:00
key: 'a-wild-sheep-chase',
disabled: true,
icon: renderIcon(bookIcon)
},
{
2020-10-22 17:25:26 +08:00
title: '舞,舞,舞',
key: 'Dance Dance Dance',
icon: renderIcon(bookIcon),
children: [
{
type: 'group',
2020-10-22 17:25:26 +08:00
title: 'People',
key: 'people',
children: [
{
title: 'Narrator',
2020-10-22 17:25:26 +08:00
key: 'narrator',
icon: renderIcon(personIcon)
},
{
title: 'Sheep Man',
2020-10-22 17:25:26 +08:00
key: 'sheep-man',
icon: renderIcon(personIcon)
}
]
},
{
title: 'Beverage',
2020-10-22 17:25:26 +08:00
key: 'beverage',
icon: renderIcon(wineIcon),
children: [
{
title: 'Whisky',
2020-10-22 17:25:26 +08:00
key: 'whisky'
}
]
},
{
title: 'Food',
2020-10-22 17:25:26 +08:00
key: 'food',
children: [
{
title: 'Sandwich',
2020-10-22 17:25:26 +08:00
key: 'sandwich'
}
]
},
{
title: 'The past increases. The future recedes.',
2020-10-22 17:25:26 +08:00
key: 'the-past-increases-the-future-recedes'
}
]
}
]
2020-02-07 22:31:26 +08:00
export default {
data () {
return {
2020-10-22 17:25:26 +08:00
activeKey: null,
menuItems
2020-02-07 22:31:26 +08:00
}
}
}
```
```css
.n-menu-item {
padding-right: 16px;
}
2020-10-22 17:25:26 +08:00
```