diff --git a/dist/mixins/basic.js b/dist/mixins/basic.js index 3754e11a..b6532124 100644 --- a/dist/mixins/basic.js +++ b/dist/mixins/basic.js @@ -9,7 +9,13 @@ export const basic = Behavior({ wx.createSelectorQuery() .in(this)[all ? 'selectAll' : 'select'](selector) .boundingClientRect(rect => { - rect && resolve(rect); + if (all && Array.isArray(rect) && rect.length) { + resolve(rect); + } + + if (!all && rect) { + resolve(rect); + } }) .exec(); }); diff --git a/dist/tab/index.js b/dist/tab/index.js index 950b4c63..64564a7d 100644 --- a/dist/tab/index.js +++ b/dist/tab/index.js @@ -2,13 +2,22 @@ import { create } from '../common/create'; create({ props: { - disabled: Boolean, + disabled: { + type: Boolean, + observer() { + const parent = this.getRelationNodes('../tabs/index')[0]; + if (parent) { + parent.updateTabs(); + } + } + }, title: { type: String, observer() { const parent = this.getRelationNodes('../tabs/index')[0]; if (parent) { parent.setLine(); + parent.updateTabs(); } } } diff --git a/dist/tabs/index.js b/dist/tabs/index.js index 7aabbef2..91cb829d 100644 --- a/dist/tabs/index.js +++ b/dist/tabs/index.js @@ -5,21 +5,16 @@ create({ '../tab/index': { type: 'descendant', - linked(target) { - const { tabs } = this.data; - tabs.push({ - instance: target, - data: target.data + linked(child) { + this.data.tabs.push({ + instance: child, + data: child.data }); - this.setData({ - tabs, - scrollable: tabs.length > this.data.swipeThreshold - }); - this.setActiveTab(); + this.updateTabs(); }, - unlinked(target) { - const tabs = this.data.tabs.filter(item => item.instance !== target); + unlinked(child) { + const tabs = this.data.tabs.filter(item => item.instance !== child); this.setData({ tabs, scrollable: tabs.length > this.data.swipeThreshold @@ -40,7 +35,8 @@ create({ }, active: { type: null, - value: 0 + value: 0, + observer: 'setActiveTab' }, type: { type: String, @@ -73,6 +69,15 @@ create({ }, methods: { + updateTabs() { + const { tabs } = this.data; + this.setData({ + tabs, + scrollable: tabs.length > this.data.swipeThreshold + }); + this.setActiveTab(); + }, + trigger(eventName, index) { this.$emit(eventName, { index, @@ -95,8 +100,6 @@ create({ this.trigger('change', active); this.setData({ active }); this.setActiveTab(); - this.setLine(); - this.scrollIntoView(); } }, @@ -138,6 +141,9 @@ create({ item.instance.setData(data); } }); + + this.setLine(); + this.scrollIntoView(); }, // scroll active tab into view diff --git a/packages/mixins/basic.js b/packages/mixins/basic.js index 3754e11a..b6532124 100644 --- a/packages/mixins/basic.js +++ b/packages/mixins/basic.js @@ -9,7 +9,13 @@ export const basic = Behavior({ wx.createSelectorQuery() .in(this)[all ? 'selectAll' : 'select'](selector) .boundingClientRect(rect => { - rect && resolve(rect); + if (all && Array.isArray(rect) && rect.length) { + resolve(rect); + } + + if (!all && rect) { + resolve(rect); + } }) .exec(); }); diff --git a/packages/tab/index.js b/packages/tab/index.js index 950b4c63..64564a7d 100644 --- a/packages/tab/index.js +++ b/packages/tab/index.js @@ -2,13 +2,22 @@ import { create } from '../common/create'; create({ props: { - disabled: Boolean, + disabled: { + type: Boolean, + observer() { + const parent = this.getRelationNodes('../tabs/index')[0]; + if (parent) { + parent.updateTabs(); + } + } + }, title: { type: String, observer() { const parent = this.getRelationNodes('../tabs/index')[0]; if (parent) { parent.setLine(); + parent.updateTabs(); } } } diff --git a/packages/tabs/index.js b/packages/tabs/index.js index 7aabbef2..91cb829d 100644 --- a/packages/tabs/index.js +++ b/packages/tabs/index.js @@ -5,21 +5,16 @@ create({ '../tab/index': { type: 'descendant', - linked(target) { - const { tabs } = this.data; - tabs.push({ - instance: target, - data: target.data + linked(child) { + this.data.tabs.push({ + instance: child, + data: child.data }); - this.setData({ - tabs, - scrollable: tabs.length > this.data.swipeThreshold - }); - this.setActiveTab(); + this.updateTabs(); }, - unlinked(target) { - const tabs = this.data.tabs.filter(item => item.instance !== target); + unlinked(child) { + const tabs = this.data.tabs.filter(item => item.instance !== child); this.setData({ tabs, scrollable: tabs.length > this.data.swipeThreshold @@ -40,7 +35,8 @@ create({ }, active: { type: null, - value: 0 + value: 0, + observer: 'setActiveTab' }, type: { type: String, @@ -73,6 +69,15 @@ create({ }, methods: { + updateTabs() { + const { tabs } = this.data; + this.setData({ + tabs, + scrollable: tabs.length > this.data.swipeThreshold + }); + this.setActiveTab(); + }, + trigger(eventName, index) { this.$emit(eventName, { index, @@ -95,8 +100,6 @@ create({ this.trigger('change', active); this.setData({ active }); this.setActiveTab(); - this.setLine(); - this.scrollIntoView(); } }, @@ -138,6 +141,9 @@ create({ item.instance.setData(data); } }); + + this.setLine(); + this.scrollIntoView(); }, // scroll active tab into view