[Improvement] Tab: add change event (#1503)

This commit is contained in:
neverland 2018-07-19 10:11:05 +08:00 committed by GitHub
parent 9da3e0ce5a
commit b7b2ad9ffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -165,4 +165,5 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click tab | indexindex of current tabtitle: tab title |
| change | Triggered when active tab changed | indexindex of current tabtitle: tab title |
| disabled | Triggered when click disabled tab | indexindex of current tab, title: tab title |

View File

@ -167,5 +167,5 @@ export default {
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击标签时触发 | index标签索引title标题 |
| change | 当前激活的标签改变时触发 | index标签索引title标题 |
| disabled | 点击被禁用的标签时触发 | index标签索引title标题 |

View File

@ -71,7 +71,7 @@ export default create({
return {
tabs: [],
position: 'content-top',
curActive: 0,
curActive: null,
lineStyle: {},
events: {
resize: false,
@ -236,8 +236,14 @@ export default create({
},
setCurActive(active) {
this.curActive = active;
this.$emit('input', active);
if (active !== this.curActive) {
this.$emit('input', active);
if (this.curActive !== null) {
this.$emit('change', active, this.tabs[active].title);
}
this.curActive = active;
}
},
// emit event when clicked
@ -246,8 +252,8 @@ export default create({
if (disabled) {
this.$emit('disabled', index, title);
} else {
this.$emit('click', index, title);
this.setCurActive(index);
this.$emit('click', index, title);
}
},