瀏覽代碼

Menu: add support for el-menu-item without index (#13298)

georgyfarniev 6 年之前
父節點
當前提交
57f3960927

+ 1 - 1
examples/docs/en-US/menu.md

@@ -341,7 +341,7 @@ Vertical NavMenu could be collapsed.
 ### Menu-Item Attribute
 | Attribute      | Description          | Type      | Accepted Values       | Default  |
 |---------- |-------- |---------- |-------------  |-------- |
-| index     | unique identification   | string  | — | — |
+| index     | unique identification   | string/null  | — | null |
 | route     | Vue Router object   | object | — | — |
 | disabled | whether disabled | boolean | — | false |
 

+ 1 - 1
examples/docs/es/menu.md

@@ -333,7 +333,7 @@ NavMenu vertical puede ser colapsado.
 ### Atributos SubMenu 
 | Atributo     | Descripción                              | Tipo   | Valores aceptados | Por defecto |
 | ------------ | ---------------------------------------- | ------ | ----------------- | ----------- |
-| index        | identificador único                      | string | —                 | —           |
+| index        | identificador único                      | string/null | —            | null        |
 | popper-class | nombre personalizado de la clase del menu popup | string | —                 | —           |
 | show-timeout | tiempo de espera antes de mostrar un submenú | number | —                 | 300         |
 | hide-timeout | tiempo de espera antes de ocultar un submenú | number | —                 | 300         |

+ 1 - 1
examples/docs/fr-FR/menu.md

@@ -347,7 +347,7 @@ Le menu vertical peut être réduit.
 
 | Attributs      | Description          | Type      | Valeurs acceptées       | Défaut  |
 |---------- |-------- |---------- |-------------  |-------- |
-| index     | Identificateur unique. | string  | — | — |
+| index     | Identificateur unique. | string/null  | — | null |
 | route     | Objet Vue Router. | object | — | — |
 | disabled | Si l'item est désactivé. | boolean | — | false |
 

+ 1 - 1
examples/docs/zh-CN/menu.md

@@ -327,7 +327,7 @@
 ### SubMenu Attribute
 | 参数      | 说明    | 类型      | 可选值       | 默认值   |
 |---------- |-------- |---------- |-------------  |-------- |
-| index     | 唯一标志   | string  | — | — |
+| index     | 唯一标志   | string/null  | — | null |
 | popper-class | 弹出菜单的自定义类名 | string | — | — |
 | show-timeout | 展开 sub-menu 的延时 | number | — | 300 |
 | hide-timeout | 收起 sub-menu 的延时 | number | — | 300 |

+ 2 - 2
packages/menu/src/menu-item.vue

@@ -44,8 +44,8 @@
 
     props: {
       index: {
-        type: String,
-        required: true
+        default: null,
+        validator: val => typeof val === 'string' || val === null
       },
       route: [String, Object],
       disabled: Boolean

+ 6 - 2
packages/menu/src/menu.vue

@@ -251,15 +251,19 @@
       handleItemClick(item) {
         const { index, indexPath } = item;
         const oldActiveIndex = this.activeIndex;
+        const hasIndex = item.index !== null;
+
+        if (hasIndex) {
+          this.activeIndex = item.index;
+        }
 
-        this.activeIndex = item.index;
         this.$emit('select', index, indexPath, item);
 
         if (this.mode === 'horizontal' || this.collapse) {
           this.openedMenus = [];
         }
 
-        if (this.router) {
+        if (this.router && hasIndex) {
           this.routeToItem(item, (error) => {
             this.activeIndex = oldActiveIndex;
             if (error) console.error(error);

+ 1 - 1
types/submenu.d.ts

@@ -3,7 +3,7 @@ import { ElementUIComponent } from './component'
 /** Submenu Component */
 export declare class ElSubmenu extends ElementUIComponent {
   /** Unique identification */
-  index: string
+  index: string | null
 
   /** Delay time before showing a sub-menu */
   showTimeout: number