From c1da495cb7f0ff0c97bee769cda8464ed775d6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Tue, 7 May 2019 10:06:57 +0800 Subject: [PATCH] [improvement] Tabs: use relation mixin --- packages/tab/index.js | 20 ++--------- .../tab/test/__snapshots__/index.spec.js.snap | 33 ++++++++--------- packages/tab/test/index.spec.js | 2 ++ packages/tabs/index.js | 36 +++++++++++-------- 4 files changed, 43 insertions(+), 48 deletions(-) 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