2016-11-10 21:46:55 +08:00
## NavMenu
Menu that provides navigation for your website.
### Top bar
Top bar NavMenu can be used in a variety of scenarios.
2017-12-12 12:45:09 +08:00
:::demo By default Menu is vertical, but you can change it to horizontal by setting the mode prop to 'horizontal'. In addition, you can use the submenu component to create a second level menu. Menu provides `background-color` , `text-color` and `active-text-color` to customize the colors.
2016-11-10 21:46:55 +08:00
```html
2017-09-16 20:50:19 +08:00
< el-menu :default-active = "activeIndex" class = "el-menu-demo" mode = "horizontal" @select =" handleSelect " >
2016-11-10 21:46:55 +08:00
< el-menu-item index = "1" > Processing Center< / el-menu-item >
2018-01-08 13:38:51 +08:00
< el-submenu index = "2" >
2016-11-10 21:46:55 +08:00
< template slot = "title" > Workspace< / template >
< el-menu-item index = "2-1" > item one< / el-menu-item >
< el-menu-item index = "2-2" > item two< / el-menu-item >
< el-menu-item index = "2-3" > item three< / el-menu-item >
2018-02-09 11:05:37 +08:00
< el-submenu index = "2-4" >
< template slot = "title" > item four< / template >
< el-menu-item index = "2-4-1" > item one< / el-menu-item >
< el-menu-item index = "2-4-2" > item two< / el-menu-item >
< el-menu-item index = "2-4-3" > item three< / el-menu-item >
< / el-submenu >
2016-11-10 21:46:55 +08:00
< / el-submenu >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "3" disabled > Info< / el-menu-item >
< el-menu-item index = "4" > < a href = "https://www.ele.me" target = "_blank" > Orders< / a > < / el-menu-item >
2016-11-10 21:46:55 +08:00
< / el-menu >
< div class = "line" > < / div >
2017-09-16 20:50:19 +08:00
< el-menu
:default-active="activeIndex2"
class="el-menu-demo"
mode="horizontal"
@select ="handleSelect"
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b">
2016-11-10 21:46:55 +08:00
< el-menu-item index = "1" > Processing Center< / el-menu-item >
< el-submenu index = "2" >
< template slot = "title" > Workspace< / template >
< el-menu-item index = "2-1" > item one< / el-menu-item >
< el-menu-item index = "2-2" > item two< / el-menu-item >
< el-menu-item index = "2-3" > item three< / el-menu-item >
2018-02-09 11:05:37 +08:00
< el-submenu index = "2-4" >
< template slot = "title" > item four< / template >
< el-menu-item index = "2-4-1" > item one< / el-menu-item >
< el-menu-item index = "2-4-2" > item two< / el-menu-item >
< el-menu-item index = "2-4-3" > item three< / el-menu-item >
< / el-submenu >
2016-11-10 21:46:55 +08:00
< / el-submenu >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "3" disabled > Info< / el-menu-item >
< el-menu-item index = "4" > < a href = "https://www.ele.me" target = "_blank" > Orders< / a > < / el-menu-item >
2016-11-10 21:46:55 +08:00
< / el-menu >
2016-11-14 18:10:52 +08:00
< script >
export default {
2017-02-17 11:29:27 +08:00
data() {
return {
activeIndex: '1',
activeIndex2: '1'
};
},
2016-11-14 18:10:52 +08:00
methods: {
handleSelect(key, keyPath) {
console.log(key, keyPath);
}
}
}
< / script >
```
2016-11-10 21:46:55 +08:00
:::
### Side bar
Vertical NavMenu with sub-menus.
2017-12-12 12:45:09 +08:00
:::demo You can use the el-menu-item-group component to create a menu group, and the name of the group is determined by the title prop or a named slot.
2016-11-10 21:46:55 +08:00
```html
< el-row class = "tac" >
2017-09-16 20:50:19 +08:00
< el-col :span = "12" >
< h5 > Default colors< / h5 >
< el-menu
default-active="2"
class="el-menu-vertical-demo"
@open ="handleOpen"
@close ="handleClose">
2016-11-10 21:46:55 +08:00
< el-submenu index = "1" >
2017-09-16 20:50:19 +08:00
< template slot = "title" >
2017-10-18 16:12:54 +08:00
< i class = "el-icon-location" > < / i >
2017-09-16 20:50:19 +08:00
< span > Navigator One< / span >
< / template >
2016-11-10 21:46:55 +08:00
< el-menu-item-group title = "Group One" >
< el-menu-item index = "1-1" > item one< / el-menu-item >
< el-menu-item index = "1-2" > item one< / el-menu-item >
< / el-menu-item-group >
< el-menu-item-group title = "Group Two" >
< el-menu-item index = "1-3" > item three< / el-menu-item >
< / el-menu-item-group >
2016-12-19 23:45:40 +08:00
< el-submenu index = "1-4" >
< template slot = "title" > item four< / template >
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
< / el-submenu >
2016-11-10 21:46:55 +08:00
< / el-submenu >
2017-09-16 20:50:19 +08:00
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
< span > Navigator Two< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
2017-09-16 20:50:19 +08:00
< span > Navigator Three< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
< span > Navigator Four< / span >
< / el-menu-item >
2016-11-10 21:46:55 +08:00
< / el-menu >
< / el-col >
2017-09-16 20:50:19 +08:00
< el-col :span = "12" >
< h5 > Custom colors< / h5 >
< el-menu
default-active="2"
class="el-menu-vertical-demo"
@open ="handleOpen"
@close ="handleClose"
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b">
2016-11-10 21:46:55 +08:00
< el-submenu index = "1" >
2017-09-16 20:50:19 +08:00
< template slot = "title" >
2017-10-18 16:12:54 +08:00
< i class = "el-icon-location" > < / i >
2017-09-16 20:50:19 +08:00
< span > Navigator One< / span >
< / template >
2016-11-10 21:46:55 +08:00
< el-menu-item-group title = "Group One" >
< el-menu-item index = "1-1" > item one< / el-menu-item >
2017-09-16 20:50:19 +08:00
< el-menu-item index = "1-2" > item one< / el-menu-item >
2016-11-10 21:46:55 +08:00
< / el-menu-item-group >
< el-menu-item-group title = "Group Two" >
< el-menu-item index = "1-3" > item three< / el-menu-item >
< / el-menu-item-group >
2016-12-19 23:45:40 +08:00
< el-submenu index = "1-4" >
< template slot = "title" > item four< / template >
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
< / el-submenu >
2016-11-10 21:46:55 +08:00
< / el-submenu >
2017-09-16 20:50:19 +08:00
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
< span > Navigator Two< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
2017-09-16 20:50:19 +08:00
< span > Navigator Three< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
< span > Navigator Four< / span >
< / el-menu-item >
2016-11-10 21:46:55 +08:00
< / el-menu >
< / el-col >
< / el-row >
2016-11-14 18:10:52 +08:00
< script >
export default {
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
2017-07-20 12:44:52 +08:00
### Collapse
Vertical NavMenu could be collapsed.
2017-12-12 12:45:09 +08:00
:::demo
2017-07-20 12:44:52 +08:00
```html
< el-radio-group v-model = "isCollapse" style = "margin-bottom: 20px;" >
< el-radio-button :label = "false" > expand< / el-radio-button >
< el-radio-button :label = "true" > collapse< / el-radio-button >
< / el-radio-group >
< el-menu default-active = "2" class = "el-menu-vertical-demo" @open =" handleOpen " @close =" handleClose " :collapse = "isCollapse" >
< el-submenu index = "1" >
< template slot = "title" >
2017-10-18 16:12:54 +08:00
< i class = "el-icon-location" > < / i >
2017-07-20 12:44:52 +08:00
< span slot = "title" > Navigator One< / span >
< / template >
< el-menu-item-group >
< span slot = "title" > Group One< / span >
< el-menu-item index = "1-1" > item one< / el-menu-item >
< el-menu-item index = "1-2" > item two< / el-menu-item >
< / el-menu-item-group >
< el-menu-item-group title = "Group Two" >
< el-menu-item index = "1-3" > item three< / el-menu-item >
< / el-menu-item-group >
< el-submenu index = "1-4" >
< span slot = "title" > item four< / span >
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
< / el-submenu >
< / el-submenu >
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
< span slot = "title" > Navigator Two< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
2017-07-20 12:44:52 +08:00
< span slot = "title" > Navigator Three< / span >
< / el-menu-item >
2018-02-11 14:59:46 +08:00
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
< span slot = "title" > Navigator Four< / span >
< / el-menu-item >
2017-07-20 12:44:52 +08:00
< / el-menu >
2017-07-30 11:25:39 +08:00
< style >
.el-menu-vertical-demo:not(.el-menu--collapse) {
width: 200px;
min-height: 400px;
}
< / style >
2017-07-20 12:44:52 +08:00
< script >
export default {
data() {
return {
2017-07-30 11:25:39 +08:00
isCollapse: true
2017-07-20 12:44:52 +08:00
};
},
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
}
}
}
< / script >
```
:::
2016-11-10 21:46:55 +08:00
### Menu Attribute
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
2017-10-18 18:31:03 +08:00
| mode | menu display mode | string | horizontal / vertical | vertical |
2017-07-20 12:44:52 +08:00
| collapse | whether the menu is collapsed (available only in vertical mode) | boolean | — | false |
2017-09-16 20:50:19 +08:00
| background-color | background color of Menu (hex format) | string | — | #ffffff |
2017-12-12 12:45:09 +08:00
| text-color | text color of Menu (hex format) | string | — | #303133 |
2017-09-30 15:50:04 +08:00
| active-text-color | text color of currently active menu item (hex format) | string | — | #409EFF |
2016-11-10 21:46:55 +08:00
| default-active | index of currently active menu | string | — | — |
2018-03-22 20:00:04 +08:00
| default-openeds | array that contains indexes of currently active sub-menus | Array | — | — |
2016-11-10 21:46:55 +08:00
| unique-opened | whether only one sub-menu can be active | boolean | — | false |
2018-08-09 13:32:05 +08:00
| menu-trigger | how sub-menus are triggered, only works when `mode` is 'horizontal' | string | hover / click | hover |
2016-11-10 21:46:55 +08:00
| router | whether `vue-router` mode is activated. If true, index will be used as 'path' to activate the route action | boolean | — | false |
2018-03-16 21:42:11 +08:00
| collapse-transition | whether to enable the collapse transition | boolean | — | true |
2016-11-10 21:46:55 +08:00
2017-10-12 16:20:16 +08:00
### Menu Methods
2018-10-15 18:38:57 +08:00
| Methods Name | Description | Parameters |
2017-10-12 16:20:16 +08:00
|---------- |-------- |---------- |
| open | open a specific sub-menu | index: index of the sub-menu to open |
| close | close a specific sub-menu | index: index of the sub-menu to close |
2016-11-10 21:46:55 +08:00
### Menu Events
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| select | callback function when menu is activated | index: index of activated menu, indexPath: index path of activated menu |
| open | callback function when sub-menu expands | index: index of expanded sub-menu, indexPath: index path of expanded sub-menu |
| close | callback function when sub-menu collapses | index: index of collapsed sub-menu, indexPath: index path of collapsed sub-menu |
2017-02-04 11:20:04 +08:00
### Menu-Item Events
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| click | callback function when menu-item is clicked | el: menu-item instance |
2016-11-10 21:46:55 +08:00
### SubMenu Attribute
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| index | unique identification | string | — | — |
2018-02-01 15:05:07 +08:00
| popper-class | custom class name for the popup menu | string | — | — |
2018-01-08 13:38:51 +08:00
| show-timeout | timeout before showing a sub-menu | number | — | 300 |
| hide-timeout | timeout before hiding a sub-menu | number | — | 300 |
2018-02-12 17:10:18 +08:00
| disabled | whether the sub-menu is disabled | boolean | — | false |
2018-04-02 17:18:50 +08:00
| popper-append-to-body | whether to append the popup menu to body. If the positioning of the menu is wrong, you can try setting this prop | boolean | - | level one Submenu: true / other Submenus: false |
2016-11-10 21:46:55 +08:00
### Menu-Item Attribute
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
2019-02-22 19:25:38 +08:00
| index | unique identification | string/null | — | null |
2016-11-10 21:46:55 +08:00
| route | Vue Router object | object | — | — |
2018-02-11 14:59:46 +08:00
| disabled | whether disabled | boolean | — | false |
2016-11-10 21:46:55 +08:00
### Menu-Group Attribute
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
| title | group title | string | — | — |