diff --git a/packages/tab/index.js b/packages/tab/index.js index b1e1ebf02..543be11d5 100644 --- a/packages/tab/index.js +++ b/packages/tab/index.js @@ -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; diff --git a/packages/tab/test/__snapshots__/index.spec.js.snap b/packages/tab/test/__snapshots__/index.spec.js.snap index e4f222d63..2f6f223f6 100644 --- a/packages/tab/test/__snapshots__/index.spec.js.snap +++ b/packages/tab/test/__snapshots__/index.spec.js.snap @@ -6,15 +6,16 @@ exports[`change tabs data 1`] = `
title1
-
+
+
title2
+
title3
-
Text
+
Text
-
Text
+
Text
@@ -105,7 +106,7 @@ exports[`lazy render 1`] = `
-
Text
+
Text
-
Text
+
Text
@@ -149,7 +150,7 @@ exports[`render nav-left & nav-right slot 1`] = `
-
Text
+
Text