mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 11:17:41 +00:00
[improvement] Tab: jsx (#2659)
This commit is contained in:
68
packages/tab/index.js
Normal file
68
packages/tab/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
import { use } from '../utils';
|
||||
import findParent from '../mixins/find-parent';
|
||||
|
||||
const [sfc, bem] = use('tab');
|
||||
|
||||
export default sfc({
|
||||
mixins: [findParent],
|
||||
|
||||
props: {
|
||||
title: String,
|
||||
disabled: Boolean
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
inited: false
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
index() {
|
||||
return this.parent.tabs.indexOf(this);
|
||||
},
|
||||
|
||||
selected() {
|
||||
return this.index === this.parent.curActive;
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'parent.curActive'() {
|
||||
this.inited = this.inited || this.selected;
|
||||
},
|
||||
|
||||
title() {
|
||||
this.parent.setLine();
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.findParent('van-tabs');
|
||||
},
|
||||
|
||||
mounted() {
|
||||
const { tabs } = this.parent;
|
||||
const index = this.parent.$slots.default.indexOf(this.$vnode);
|
||||
tabs.splice(index === -1 ? tabs.length : index, 0, this);
|
||||
|
||||
if (this.$slots.title) {
|
||||
this.parent.renderTitle(this.$refs.title, this.index);
|
||||
}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.parent.tabs.splice(this.index, 1);
|
||||
},
|
||||
|
||||
render(h) {
|
||||
const slots = this.$slots;
|
||||
return (
|
||||
<div v-show={this.selected || this.parent.animated} class={bem('pane')}>
|
||||
{this.inited && slots.default}
|
||||
{slots.title && <div ref="title">{slots.title}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user