2020-08-13 15:18:26 +08:00
## NavMenu
Menu that provides navigation for your website.
### Top bar
Top bar NavMenu can be used in a variety of scenarios.
2021-08-25 10:03:36 +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 sub-menu component to create a second level menu. Menu provides `background-color` , `text-color` and `active-text-color` to customize the colors.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
2021-09-04 19:29:28 +08:00
< el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
@select ="handleSelect"
>
2020-08-13 15:18:26 +08:00
< el-menu-item index = "1" > Processing Center< / el-menu-item >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "2" >
2020-11-12 16:46:12 +08:00
< template #title > Workspace</ template >
2020-08-13 15:18:26 +08:00
< 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 >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "2-4" >
2020-11-12 16:46:12 +08:00
< template #title > item four</ template >
2020-08-13 15:18:26 +08:00
< 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 >
2021-08-25 10:03:36 +08:00
< / el-sub-menu >
< / el-sub-menu >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "3" disabled > Info< / el-menu-item >
2021-08-31 15:31:48 +08:00
< el-menu-item index = "4" > Orders< / el-menu-item >
2020-08-13 15:18:26 +08:00
< / el-menu >
< div class = "line" > < / div >
< el-menu
:default-active="activeIndex2"
class="el-menu-demo"
mode="horizontal"
@select ="handleSelect"
background-color="#545c64"
text-color="#fff"
2021-09-04 19:29:28 +08:00
active-text-color="#ffd04b"
>
2020-08-13 15:18:26 +08:00
< el-menu-item index = "1" > Processing Center< / el-menu-item >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "2" >
2020-11-12 16:46:12 +08:00
< template #title > Workspace</ template >
2020-08-13 15:18:26 +08:00
< 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 >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "2-4" >
2020-11-12 16:46:12 +08:00
< template #title > item four</ template >
2020-08-13 15:18:26 +08:00
< 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 >
2021-08-25 10:03:36 +08:00
< / el-sub-menu >
< / el-sub-menu >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "3" disabled > Info< / el-menu-item >
2021-08-31 15:31:48 +08:00
< el-menu-item index = "4" > Orders< / el-menu-item >
2020-08-13 15:18:26 +08:00
< / el-menu >
< script >
export default {
data() {
return {
activeIndex: '1',
2021-09-04 19:29:28 +08:00
activeIndex2: '1',
}
2020-08-13 15:18:26 +08:00
},
methods: {
handleSelect(key, keyPath) {
2021-09-04 19:29:28 +08:00
console.log(key, keyPath)
},
},
2020-08-13 15:18:26 +08:00
}
< / script >
2021-06-19 02:23:50 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const activeIndex = ref('1');
const activeIndex2 = ref('1');
const handleSelect = (key, keyPath) => {
console.log(key, keyPath);
};
return {
activeIndex,
activeIndex2,
handleSelect,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Side bar
Vertical NavMenu with sub-menus.
:::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.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
< el-row class = "tac" >
< el-col :span = "12" >
< h5 > Default colors< / h5 >
< el-menu
default-active="2"
class="el-menu-vertical-demo"
@open ="handleOpen"
2021-09-04 19:29:28 +08:00
@close ="handleClose"
>
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1" >
2020-11-12 16:46:12 +08:00
< template #title >
2020-08-13 15:18:26 +08:00
< i class = "el-icon-location" > < / i >
< span > Navigator One< / span >
< / template >
< 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 >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1-4" >
2020-11-12 16:46:12 +08:00
< template #title > item four</ template >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
2021-08-25 10:03:36 +08:00
< / el-sub-menu >
< / el-sub-menu >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
< span > Navigator Two< / span >
< / el-menu-item >
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
< span > Navigator Three< / span >
< / el-menu-item >
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
< span > Navigator Four< / span >
< / el-menu-item >
< / el-menu >
< / el-col >
< 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"
2021-09-04 19:29:28 +08:00
active-text-color="#ffd04b"
>
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1" >
2020-11-12 16:46:12 +08:00
< template #title >
2020-08-13 15:18:26 +08:00
< i class = "el-icon-location" > < / i >
< span > Navigator One< / span >
< / template >
< 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 >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1-4" >
2020-11-12 16:46:12 +08:00
< template #title > item four</ template >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
2021-08-25 10:03:36 +08:00
< / el-sub-menu >
< / el-sub-menu >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
< span > Navigator Two< / span >
< / el-menu-item >
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
< span > Navigator Three< / span >
< / el-menu-item >
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
< span > Navigator Four< / span >
< / el-menu-item >
< / el-menu >
< / el-col >
< / el-row >
< script >
export default {
methods: {
handleOpen(key, keyPath) {
2021-09-04 19:29:28 +08:00
console.log(key, keyPath)
2020-08-13 15:18:26 +08:00
},
handleClose(key, keyPath) {
2021-09-04 19:29:28 +08:00
console.log(key, keyPath)
},
},
2020-08-13 15:18:26 +08:00
}
< / script >
2021-06-19 02:23:50 +08:00
<!--
< setup >
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
const handleOpen = (key, keyPath) => {
console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
console.log(key, keyPath);
};
return {
handleOpen,
handleClose,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Collapse
Vertical NavMenu could be collapsed.
:::demo
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +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 >
2021-09-04 19:29:28 +08:00
< el-menu
default-active="2"
class="el-menu-vertical-demo"
@open ="handleOpen"
@close ="handleClose"
:collapse="isCollapse"
>
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1" >
2020-11-12 16:46:12 +08:00
< template #title >
2020-08-13 15:18:26 +08:00
< i class = "el-icon-location" > < / i >
2020-11-12 16:46:12 +08:00
< span > Navigator One< / span >
2020-08-13 15:18:26 +08:00
< / template >
< el-menu-item-group >
2020-11-12 16:46:12 +08:00
< template #title >< span > Group One</ span ></ template >
2020-08-13 15:18:26 +08:00
< 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 >
2021-08-25 10:03:36 +08:00
< el-sub-menu index = "1-4" >
2020-11-12 16:46:12 +08:00
< template #title >< span > item four</ span ></ template >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "1-4-1" > item one< / el-menu-item >
2021-08-25 10:03:36 +08:00
< / el-sub-menu >
< / el-sub-menu >
2020-08-13 15:18:26 +08:00
< el-menu-item index = "2" >
< i class = "el-icon-menu" > < / i >
2020-11-12 16:46:12 +08:00
< template #title > Navigator Two</ template >
2020-08-13 15:18:26 +08:00
< / el-menu-item >
< el-menu-item index = "3" disabled >
< i class = "el-icon-document" > < / i >
2020-11-12 16:46:12 +08:00
< template #title > Navigator Three</ template >
2020-08-13 15:18:26 +08:00
< / el-menu-item >
< el-menu-item index = "4" >
< i class = "el-icon-setting" > < / i >
2020-11-12 16:46:12 +08:00
< template #title > Navigator Four</ template >
2020-08-13 15:18:26 +08:00
< / el-menu-item >
< / el-menu >
< style >
.el-menu-vertical-demo:not(.el-menu--collapse) {
width: 200px;
min-height: 400px;
}
< / style >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
isCollapse: true,
}
2020-08-13 15:18:26 +08:00
},
methods: {
handleOpen(key, keyPath) {
2021-09-04 19:29:28 +08:00
console.log(key, keyPath)
2020-08-13 15:18:26 +08:00
},
handleClose(key, keyPath) {
2021-09-04 19:29:28 +08:00
console.log(key, keyPath)
},
},
2020-08-13 15:18:26 +08:00
}
< / script >
2021-06-19 02:23:50 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const isCollapse = ref(true);
const handleOpen = (key, keyPath) => {
console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
console.log(key, keyPath);
};
return {
isCollapse,
handleOpen,
handleClose,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
2021-04-06 11:41:02 +08:00
### Menu Attributes
2021-09-04 19:29:28 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| ------------------- | ---------------------------------------------------------------------------------------------------------- | ------- | --------------------- | -------- |
| mode | menu display mode | string | horizontal / vertical | vertical |
| collapse | whether the menu is collapsed (available only in vertical mode) | boolean | — | false |
| background-color | background color of Menu (hex format) | string | — | #ffffff |
| text-color | text color of Menu (hex format) | string | — | #303133 |
| active-text-color | text color of currently active menu item (hex format) | string | — | #409EFF |
| default-active | index of currently active menu | string | — | — |
| default-openeds | array that contains indexes of currently active sub-menus | Array | — | — |
| unique-opened | whether only one sub-menu can be active | boolean | — | false |
| menu-trigger | how sub-menus are triggered, only works when `mode` is 'horizontal' | string | hover / click | hover |
| router | whether `vue-router` mode is activated. If true, index will be used as 'path' to activate the route action | boolean | — | false |
| collapse-transition | whether to enable the collapse transition | boolean | — | true |
2020-08-13 15:18:26 +08:00
### Menu Methods
2021-09-04 19:29:28 +08:00
| Methods Name | Description | Parameters |
| ------------ | ------------------------- | ------------------------------------- |
| 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 |
2020-08-13 15:18:26 +08:00
### Menu Events
2021-09-04 19:29:28 +08:00
| Event Name | Description | Parameters |
| ---------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| select | callback function when menu is activated | index: index of activated menu, indexPath: index path of activated menu, item: the selected menu item, routeResult: result returned by `vue-router` if `router` is enabled |
| 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 |
2020-08-13 15:18:26 +08:00
### Menu-Item Events
2021-09-04 19:29:28 +08:00
| Event Name | Description | Parameters |
| ---------- | ------------------------------------------- | ---------------------- |
| click | callback function when menu-item is clicked | el: menu-item instance |
2020-08-13 15:18:26 +08:00
2021-08-25 10:03:36 +08:00
### SubMenu Attributes
2021-09-04 19:29:28 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| --------------------- | ---------------------------------------------------------------------------------------------------------------- | ------- | --------------- | ----------------------------------------------- |
| index | unique identification | string | — | — |
| popper-class | custom class name for the popup menu | string | — | — |
| show-timeout | timeout before showing a sub-menu | number | — | 300 |
| hide-timeout | timeout before hiding a sub-menu | number | — | 300 |
| disabled | whether the sub-menu is disabled | boolean | — | false |
| 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 |
2020-08-13 15:18:26 +08:00
2021-04-06 11:41:02 +08:00
### Menu-Item Attributes
2021-09-04 19:29:28 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| --------- | --------------------- | ----------- | --------------- | ------- |
| index | unique identification | string/null | — | null |
| route | Vue Router object | object | — | — |
| disabled | whether disabled | boolean | — | false |
2020-08-13 15:18:26 +08:00
2021-04-06 11:41:02 +08:00
### Menu-Item-Group Attributes
2021-09-04 19:29:28 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| --------- | ----------- | ------ | --------------- | ------- |
| title | group title | string | — | — |