From cbde527457860cd645d2d65d86395907da477e9b Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 7 Dec 2017 15:05:33 +0800 Subject: [PATCH] fix tabs bug --- components/tabs/TabBarMixin.js | 2 +- components/tabs/Tabs.vue | 22 ++++++++++++---------- components/tabs/demo/extra.vue | 10 ++++++++++ components/tabs/index.vue | 7 +++++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/components/tabs/TabBarMixin.js b/components/tabs/TabBarMixin.js index 7f148de68..3ee646752 100644 --- a/components/tabs/TabBarMixin.js +++ b/components/tabs/TabBarMixin.js @@ -98,7 +98,7 @@ export default { const tabBarExtraContentStyle = topOrBottom ? { float: 'right' } : {} let children = contents extraContent = typeof extraContent === 'function' ? extraContent(createElement) : extraContent - + extraContent = extraContent || this.$slots.extraContent if (tabsType === 'editable-card' && !hideAdd) { extraContent = ( diff --git a/components/tabs/Tabs.vue b/components/tabs/Tabs.vue index e99854e27..9ecbe5a6d 100644 --- a/components/tabs/Tabs.vue +++ b/components/tabs/Tabs.vue @@ -5,7 +5,7 @@ import TabContent from './TabContent' import ScrollableInkTabBar from './ScrollableInkTabBar' function getDefaultActiveKey (t) { let activeKey - t.$slots.default.forEach(({ componentOptions = {}}) => { + t.$slots.default && t.$slots.default.forEach(({ componentOptions = {}}) => { const child = componentOptions.propsData if (child && !activeKey && !child.disabled) { activeKey = child.tabKey @@ -14,7 +14,7 @@ function getDefaultActiveKey (t) { return activeKey } function activeKeyIsValid (t, key) { - const keys = t.$slots.default.map(({ componentOptions = {}}) => { + const keys = t.$slots.default && t.$slots.default.map(({ componentOptions = {}}) => { const child = componentOptions.propsData if (child) { return child.tabKey @@ -116,7 +116,7 @@ export default { getNextActiveKey (next) { const activeKey = this.stateActiveKey const children = [] - this.$slots.default.forEach(({ componentOptions = {}}) => { + this.$slots.default && this.$slots.default.forEach(({ componentOptions = {}}) => { const c = componentOptions.propsData if (c && !c.disabled && c.disabled !== '') { if (next) { @@ -154,13 +154,11 @@ export default { setActiveKey, $slots, } = this - const hasSlot = !!$slots.default const panels = [] - if (hasSlot) { - $slots.default.forEach(tab => { - tab.componentOptions && panels.push(tab.componentOptions.propsData) - }) - } + + $slots.default && $slots.default.forEach(tab => { + tab.componentOptions && panels.push(tab.componentOptions.propsData) + }) const tabContentProps = { props: { ...this.tabContentProps, @@ -186,7 +184,11 @@ export default { style: this.tabBarProps.style || {}, } const contents = [ - , + + {$slots.tabBarExtraContent ? + {$slots.tabBarExtraContent} + : null} + , {$slots.default} , diff --git a/components/tabs/demo/extra.vue b/components/tabs/demo/extra.vue index a0f206665..ce749923d 100644 --- a/components/tabs/demo/extra.vue +++ b/components/tabs/demo/extra.vue @@ -1,9 +1,18 @@ diff --git a/components/tabs/index.vue b/components/tabs/index.vue index 48ca53ccd..61d0529f5 100644 --- a/components/tabs/index.vue +++ b/components/tabs/index.vue @@ -81,8 +81,9 @@ export default { destroyInactiveTabPane = false, activeKey, defaultActiveKey, + $slots, } = this - const { tabBarExtraContent } = this.$props + let { tabBarExtraContent } = this.$props let { inkBarAnimated, tabPaneAnimated } = typeof animated === 'object' ? { // eslint-disable-line inkBarAnimated: !!animated.inkBar, tabPaneAnimated: !!animated.tabPane, } : { @@ -100,7 +101,9 @@ export default { [`${prefixCls}-${type}`]: true, [`${prefixCls}-no-animation`]: !tabPaneAnimated, } - + tabBarExtraContent = tabBarExtraContent || ((h) => { + return h('span', [$slots.tabBarExtraContent]) + }) const tabBarProps = { inkBarAnimated, extraContent: tabBarExtraContent,