浏览代码

Tabs: add activeName and oldActiveName parameters to before-leave hook (#11713)

* Tabs: add activeName and oldActiveName parameters to before-leave hook

* Tabs: fix docs
Jikkai Xiao 7 年之前
父节点
当前提交
ef98b75aff
共有 5 个文件被更改,包括 5 次插入5 次删除
  1. 1 1
      examples/docs/en-US/tabs.md
  2. 1 1
      examples/docs/es/tabs.md
  3. 1 1
      examples/docs/zh-CN/tabs.md
  4. 1 1
      packages/tabs/src/tabs.vue
  5. 1 1
      types/tabs.d.ts

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

@@ -377,7 +377,7 @@ Only card type Tabs support addable & closeable.
 | value  | name of the selected tab  | string   |  —  |  name of first tab |
 | tab-position  | position of tabs | string   |  top/right/bottom/left  |  top |
 | stretch  | whether width of tab automatically fits its container | boolean   |  -  |  false |
-| before-leave | hook function before switching tab. If `false` is returned or a `Promise` is returned and then is rejected, switching will be prevented | function | — | — |
+| before-leave | hook function before switching tab. If `false` is returned or a `Promise` is returned and then is rejected, switching will be prevented | Function(activeName, oldActiveName) | — | — |
 
 ### Tabs Events
 | Event Name | Description | Parameters |

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

@@ -377,7 +377,7 @@ Solo las pestañas de tipo tarjeta soportan adición y cierre.
 | value        | nombre de la pestaña seleccionada    | string  | —                     | nombre de la primer pestaña |
 | tab-position | posición de tabulación               | string  | top/right/bottom/left | top                         |
 | stretch      | si el ancho del tab se ajusta automáticamente a su contenedor | boolean | - | false |
-| before-leave | función `hook` antes de cambiar de pestaña. Si se devuelve `false` o se devuelve una `Promise` y luego se rechaza, se evitará el cambio. | function | — | — |
+| before-leave | función `hook` antes de cambiar de pestaña. Si se devuelve `false` o se devuelve una `Promise` y luego se rechaza, se evitará el cambio. | Function(activeName, oldActiveName) | — | — |
 
 ### Eventos de Pestañas
 | Nombre de Evento | Descripción                              | Parámetros                    |

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

@@ -375,7 +375,7 @@
 | value  | 绑定值,选中选项卡的 name  | string   |  —  |  第一个选项卡的 name |
 | tab-position  | 选项卡所在位置 | string   |  top/right/bottom/left  |  top |
 | stretch  | 标签的宽度是否自撑开 | boolean   |  -  |  false |
-| before-leave | 切换标签之前的钩子,若返回 false 或者返回 Promise 且被 reject,则阻止切换。 | function | — | — |
+| before-leave | 切换标签之前的钩子,若返回 false 或者返回 Promise 且被 reject,则阻止切换。 | Function(activeName, oldActiveName) | — | — |
 
 ### Tabs Events
 | 事件名称 | 说明 | 回调参数 |

+ 1 - 1
packages/tabs/src/tabs.vue

@@ -74,7 +74,7 @@
           this.$emit('input', value);
         };
         if (this.currentName !== value && this.beforeLeave) {
-          const before = this.beforeLeave();
+          const before = this.beforeLeave(value, this.currentName);
           if (before && before.then) {
             before.then(() => {
               changeCurrentName();

+ 1 - 1
types/tabs.d.ts

@@ -27,5 +27,5 @@ export declare class ElTabs extends ElementUIComponent {
   stretch: Boolean
 
   /** Hook function before switching tab. If false or a Promise is returned and then is rejected, switching will be prevented */
-  beforeLeave: () => boolean | Promise<any>
+  beforeLeave: (activeName: string, oldActiveName: string) => boolean | Promise<any>
 }