[Improvement] Tab: click event add title param (#761)

This commit is contained in:
neverland 2018-03-23 11:10:35 +08:00 committed by GitHub
parent 0521c75b9c
commit 8ed6c73528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 45 additions and 50 deletions

View File

@ -83,7 +83,7 @@ Vue.use(Vant);
<script src="https://unpkg.com/vant/lib/vant.min.js"></script> <script src="https://unpkg.com/vant/lib/vant.min.js"></script>
``` ```
See more in [Quickstart](https://www.youzanyun.com/zanui/vant#/en-US/component/quickstart). See more in [Quickstart](https://www.youzanyun.com/zanui/vant#/en-US/quickstart).
## Contribution ## Contribution

View File

@ -33,7 +33,7 @@
</demo-block> </demo-block>
<demo-block :title="$t('title5')"> <demo-block :title="$t('title5')">
<van-tabs @click="handleTabClick"> <van-tabs @click="onClick">
<van-tab v-for="index in 4" :title="$t('tab') + index" :key="index"> <van-tab v-for="index in 4" :title="$t('tab') + index" :key="index">
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
@ -80,7 +80,8 @@ export default {
title5: '点击事件', title5: '点击事件',
title6: '粘性布局', title6: '粘性布局',
title7: '自定义标签', title7: '自定义标签',
title8: '滑动切换' title8: '滑动切换',
disabled: ' 已被禁用'
}, },
'en-US': { 'en-US': {
tab: 'Tab ', tab: 'Tab ',
@ -91,7 +92,8 @@ export default {
title5: 'Click Event', title5: 'Click Event',
title6: 'Sticky', title6: 'Sticky',
title7: 'Custom Tab', title7: 'Custom Tab',
title8: 'Swipeable' title8: 'Swipeable',
disabled: ' is disabled'
} }
}, },
@ -103,12 +105,12 @@ export default {
}, },
methods: { methods: {
onClickDisabled() { onClickDisabled(index, title) {
Toast('Disabled!'); this.$toast(title + this.$t('disabled'));
}, },
handleTabClick(index) { onClick(index, title) {
Toast(index); this.$toast(title);
} }
} }
}; };

View File

@ -109,4 +109,4 @@ export default {
| address | Address | `String` | | address | Address | `String` |
#### Area Data Structure #### Area Data Structure
Please refer to [Area](#/en-US/component/area) component。 Please refer to [Area](#/en-US/area) component。

View File

@ -1,4 +1,5 @@
## Area ## Area
The Picker component is usually used with [Popup](#/en-US/popup) Component.
### Install ### Install

View File

@ -16,7 +16,7 @@
### Quickstart ### Quickstart
See in [Quickstart](https://www.youzanyun.com/zanui/vant#/en-US/component/quickstart). See in [Quickstart](https://www.youzanyun.com/zanui/vant#/en-US/quickstart).
### Contribution ### Contribution
@ -29,7 +29,7 @@ Modern browsers and Android 4.0+, iOS 6+.
### Links ### Links
* [Feedback](https://github.com/youzan/vant/issues) * [Feedback](https://github.com/youzan/vant/issues)
* [Changelog](https://www.youzanyun.com/zanui/vant#/en-US/component/changelog) * [Changelog](https://www.youzanyun.com/zanui/vant#/en-US/changelog)
* [Weapp UI](https://github.com/youzan/zanui-weapp) * [Weapp UI](https://github.com/youzan/zanui-weapp)
* [React UI](https://www.youzanyun.com/zanui/zent) * [React UI](https://www.youzanyun.com/zanui/zent)
* [Vant Demo](https://github.com/youzan/vant-demo) * [Vant Demo](https://github.com/youzan/vant-demo)

View File

@ -1,5 +1,5 @@
## PasswordInput ## PasswordInput
The PasswordInput component is usually used with [NumberKeyboard](#/en-US/component/number-keyboard) Component. The PasswordInput component is usually used with [NumberKeyboard](#/en-US/number-keyboard) Component.
### Install ### Install
``` javascript ``` javascript

View File

@ -1,4 +1,5 @@
## Picker ## Picker
The Picker component is usually used with [Popup](#/en-US/popup) Component.
### Install ### Install
``` javascript ``` javascript

View File

@ -1,4 +1,4 @@
## Tabs ## Tab
### Install ### Install
``` javascript ``` javascript
@ -58,8 +58,8 @@ You can set `disabled` attribute on the corresponding `van-tab`.
```javascript ```javascript
export default { export default {
methods: { methods: {
onClickDisabled() { onClickDisabled(index, title) {
Toast('Disabled!'); this.$toast(title + ' is disabled');
} }
} }
}; };
@ -79,10 +79,8 @@ Tabs styled as cards.
#### Click Event #### Click Event
You can bind `click` event on `van-tabs`, the event handler function has one parameters: index of click tab.
```html ```html
<van-tabs @click="handleTabClick"> <van-tabs @click="onClick">
<van-tab v-for="index in 4" :title="'tab' + index"> <van-tab v-for="index in 4" :title="'tab' + index">
content of tab {{ index }} content of tab {{ index }}
</van-tab> </van-tab>
@ -92,8 +90,8 @@ You can bind `click` event on `van-tabs`, the event handler function has one par
```javascript ```javascript
export default { export default {
methods: { methods: {
handleTabClick(index) { onClick(index, title) {
Toast(index); this.$toast(title);
} }
} }
}; };
@ -151,8 +149,8 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| title | Tab title | `String` | - | - | | title | Title | `String` | - | - |
| disabled | Whether disabled current tab | `Boolean` | `false` | - | | disabled | Whether to disable tab | `Boolean` | `false` | - |
### Tab Slot ### Tab Slot
@ -165,6 +163,5 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content
| Event | Description | Arguments | | Event | Description | Arguments |
|-----------|-----------|-----------| |-----------|-----------|-----------|
| click | Triggered when click tab | indexindex of current tab | | click | Triggered when click tab | indexindex of current tabtitle: tab title |
| disabled | Triggered when click disabled tab | indexindex of current tab | | disabled | Triggered when click disabled tab | indexindex of current tab, title: tab title |

View File

@ -1,4 +1,5 @@
## Area 省市县选择组件 ## Area 省市县选择组件
省市县选择组件通常与 [弹出层](#/zh-CN/popup) 组件配合使用
### 使用指南 ### 使用指南

View File

@ -1,4 +1,5 @@
## Picker 选择器 ## Picker 选择器
选择器组件通常与 [弹出层](#/zh-CN/popup) 组件配合使用
### 使用指南 ### 使用指南
``` javascript ``` javascript

View File

@ -1,4 +1,4 @@
## Tabs 标签页 ## Tab 标签页
### 使用指南 ### 使用指南
``` javascript ``` javascript
@ -58,8 +58,8 @@ export default {
```javascript ```javascript
export default { export default {
methods: { methods: {
onClickDisabled() { onClickDisabled(index, title) {
Toast('Disabled!') this.$toast(title + '已被禁用');
} }
} }
}; };
@ -79,10 +79,10 @@ export default {
#### 点击事件 #### 点击事件
可以在`van-tabs`上绑定一个`click`事件,事件处理函数有一个参数,参数为对应`tab``tabs`中的索引。 可以在`van-tabs`上绑定`click`事件,事件传参为标签对应的索引和标题
```html ```html
<van-tabs @click="handleTabClick"> <van-tabs @click="onClick">
<van-tab v-for="index in 4" :title="'选项 ' + index"> <van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }} 内容 {{ index }}
</van-tab> </van-tab>
@ -92,8 +92,8 @@ export default {
```javascript ```javascript
export default { export default {
methods: { methods: {
handleTabClick(index) { onClick(index, title) {
Toast(index); this.$toast(title);
} }
} }
}; };
@ -151,8 +151,8 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 可选 | | 参数 | 说明 | 类型 | 默认值 | 可选 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| title | tab的标题 | `String` | - | - | | title | 标题 | `String` | - | - |
| disabled | 是否禁用这个tab | `Boolean` | `false` | - | | disabled | 是否禁用标签 | `Boolean` | `false` | - |
### Tab Slot ### Tab Slot
@ -165,6 +165,6 @@ export default {
| 事件名 | 说明 | 参数 | | 事件名 | 说明 | 参数 |
|-----------|-----------|-----------| |-----------|-----------|-----------|
| click | 某个tab点击事件 | index点击的`tab`的索引 | | click | 点击标签时触发 | index标签索引title标题 |
| disabled | 某个tab禁用时点击事件 | index点击的`tab`的索引 | | disabled | 点击被禁用的标签时触发 | index标签索引title标题 |

View File

@ -229,10 +229,11 @@ export default create({
// emit event when clicked // emit event when clicked
onClick(index) { onClick(index) {
if (this.tabs[index].disabled) { const { title, disabled } = this.tabs[index];
this.$emit('disabled', index); if (disabled) {
this.$emit('disabled', index, title);
} else { } else {
this.$emit('click', index); this.$emit('click', index, title);
this.curActive = index; this.curActive = index;
} }
}, },

View File

@ -4,8 +4,8 @@
:duration="duration" :duration="duration"
:sticky="sticky" :sticky="sticky"
:swipeable="swipeable" :swipeable="swipeable"
@click="handleTabClick" @click="$emit('click')"
@disabled="handleTabDisabledClick" @disabled="$emit('disabled')"
> >
<van-tab :title="firstTabTitle" :disabled="firstTabDisabled">内容一</van-tab> <van-tab :title="firstTabTitle" :disabled="firstTabDisabled">内容一</van-tab>
<van-tab title="选项二">内容二</van-tab> <van-tab title="选项二">内容二</van-tab>
@ -33,15 +33,6 @@ export default {
active: 0, active: 0,
duration: 0.5 duration: 0.5
}; };
},
methods: {
handleTabClick(index) {
this.$emit('click');
},
handleTabDisabledClick(index) {
this.$emit('disabled');
}
} }
}; };
</script> </script>