mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
53 lines
942 B
Vue
53 lines
942 B
Vue
<template>
|
|
<div :class="['van-tab__pane', { 'van-tab__pane--select': key === $parent.curActive }]">
|
|
<slot></slot>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import findParent from '../mixins/findParent';
|
|
|
|
export default {
|
|
name: 'van-tab',
|
|
|
|
mixins: [findParent],
|
|
|
|
props: {
|
|
title: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
disabled: Boolean
|
|
},
|
|
|
|
data() {
|
|
this.findParentByComponentName('van-tabs');
|
|
const nextIndex = this.parentGroup.tabs.length;
|
|
this.updateParentData(nextIndex);
|
|
return {
|
|
key: nextIndex
|
|
};
|
|
},
|
|
|
|
watch: {
|
|
title() {
|
|
this.updateParentData();
|
|
},
|
|
disabled() {
|
|
this.updateParentData();
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
updateParentData(nextIndex) {
|
|
const index = arguments.length ? nextIndex : this.key;
|
|
this.parentGroup.tabs.splice(index, 1, {
|
|
title: this.title,
|
|
disabled: this.disabled,
|
|
index
|
|
});
|
|
}
|
|
}
|
|
};
|
|
</script>
|