[improvement] Tabs: use relation mixin

This commit is contained in:
陈嘉涵
2019-05-07 10:06:57 +08:00
parent 912d691f9e
commit c1da495cb7
4 changed files with 43 additions and 48 deletions

View File

@@ -1,11 +1,11 @@
/* eslint-disable object-shorthand */
import { use } from '../utils';
import { FindParentMixin } from '../mixins/find-parent';
import { ChildrenMixin } from '../mixins/relation';
const [sfc, bem] = use('tab');
export default sfc({
mixins: [FindParentMixin],
mixins: [ChildrenMixin('vanTabs')],
props: {
title: String,
@@ -19,10 +19,6 @@ export default sfc({
},
computed: {
index() {
return this.parent.tabs.indexOf(this);
},
selected() {
return this.index === this.parent.curActive;
}
@@ -38,24 +34,12 @@ export default sfc({
}
},
created() {
this.findParent('van-tabs');
},
mounted() {
const { tabs } = this.parent;
const index = this.parent.slots().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;
const shouldRender = this.inited || !this.parent.lazyRender;