From 03664d73fbfa0a1a6ba0e69506bc28418c9e0db8 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 1 Dec 2017 12:21:43 +0800 Subject: [PATCH] fix --- components/tabs/InkTabBar.vue | 4 +-- components/tabs/InkTabBarMixin.js | 5 ++- components/tabs/ScrollableInkTabBar.vue | 4 +-- components/tabs/ScrollableTabBar.vue | 4 +-- components/tabs/ScrollableTabBarMixin.js | 13 ++++---- components/tabs/TabBar.vue | 6 ++-- components/tabs/TabBarMixin.js | 10 +++--- components/tabs/TabPane.vue | 8 +++-- components/tabs/Tabs.vue | 38 ++++++++++++---------- components/tabs/demo/basic.vue | 17 ++++------ components/tabs/demo/disabled.vue | 16 +++++++++ components/tabs/demo/icon.vue | 25 +++++++++++++++ components/tabs/demo/slide.vue | 41 ++++++++++++++++++++++++ components/tabs/index.vue | 37 +++++++++++---------- components/tabs/utils.js | 6 ++-- 15 files changed, 162 insertions(+), 72 deletions(-) create mode 100644 components/tabs/demo/disabled.vue create mode 100644 components/tabs/demo/icon.vue create mode 100644 components/tabs/demo/slide.vue diff --git a/components/tabs/InkTabBar.vue b/components/tabs/InkTabBar.vue index 501bf6c3e..48dafa1d2 100644 --- a/components/tabs/InkTabBar.vue +++ b/components/tabs/InkTabBar.vue @@ -5,9 +5,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'InkTabBar', mixins: [TabBarMixin, InkTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) return this.getRootNode([inkBarNode, tabs]) }, } diff --git a/components/tabs/InkTabBarMixin.js b/components/tabs/InkTabBarMixin.js index fa27ce527..d09dc3839 100644 --- a/components/tabs/InkTabBarMixin.js +++ b/components/tabs/InkTabBarMixin.js @@ -35,7 +35,7 @@ function offset (elem) { } function componentDidUpdate (component, init) { - const { styles } = component.$props + const { styles = {}} = component.$props const wrapNode = component.$refs.nav || component.$refs.root const containerOffset = offset(wrapNode) const inkBarNode = component.$refs.inkBar @@ -111,9 +111,8 @@ export default { }, updated () { this.$nextTick(function () { - componentDidUpdate(this, true) + componentDidUpdate(this) }) - componentDidUpdate(this) }, mounted () { diff --git a/components/tabs/ScrollableInkTabBar.vue b/components/tabs/ScrollableInkTabBar.vue index e3a729727..292633176 100644 --- a/components/tabs/ScrollableInkTabBar.vue +++ b/components/tabs/ScrollableInkTabBar.vue @@ -6,9 +6,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'ScrollableInkTabBar', mixins: [TabBarMixin, InkTabBarMixin, ScrollableTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]) return this.getRootNode(scrollbarNode) }, diff --git a/components/tabs/ScrollableTabBar.vue b/components/tabs/ScrollableTabBar.vue index d041190e9..3a1e83071 100644 --- a/components/tabs/ScrollableTabBar.vue +++ b/components/tabs/ScrollableTabBar.vue @@ -5,9 +5,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'ScrollableTabBar', mixins: [TabBarMixin, ScrollableTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]) return this.getRootNode(scrollbarNode) }, diff --git a/components/tabs/ScrollableTabBarMixin.js b/components/tabs/ScrollableTabBarMixin.js index e2371a41b..3f91dd48a 100644 --- a/components/tabs/ScrollableTabBarMixin.js +++ b/components/tabs/ScrollableTabBarMixin.js @@ -53,9 +53,9 @@ export default { }, setNextPrev () { - const navNode = this.nav + const navNode = this.$refs.nav const navNodeWH = this.getOffsetWH(navNode) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) let { offset } = this const minOffset = navWrapNodeWH - navNodeWH @@ -110,7 +110,7 @@ export default { this.offset = target let navOffset = {} const tabBarPosition = this.$props.tabBarPosition - const navStyle = this.nav.style + const navStyle = this.$refs.nav.style const transformSupported = isTransformSupported(navStyle) if (tabBarPosition === 'left' || tabBarPosition === 'right') { if (transformSupported) { @@ -177,7 +177,8 @@ export default { }, scrollToActiveTab (e) { - const { activeTab, navWrap } = this + const { activeTab } = this + const navWrap = this.$refs.navWrap if (e && e.target !== e.currentTarget || !activeTab) { return } @@ -205,7 +206,7 @@ export default { prevClick (e) { this.$props.onPrevClick(e) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) const { offset } = this this.setOffset(offset + navWrapNodeWH) @@ -213,7 +214,7 @@ export default { nextClick (e) { this.$props.onNextClick(e) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) const { offset } = this this.setOffset(offset - navWrapNodeWH) diff --git a/components/tabs/TabBar.vue b/components/tabs/TabBar.vue index 4305e455b..423f97cc7 100644 --- a/components/tabs/TabBar.vue +++ b/components/tabs/TabBar.vue @@ -26,9 +26,9 @@ export default { activeKey: String, panels: Array, }, - render (createElement) { - const tabs = this.getTabs() - return this.getRootNode(tabs, createElement) + render (h) { + const tabs = this.getTabs(h) + return this.getRootNode(tabs, h) }, } diff --git a/components/tabs/TabBarMixin.js b/components/tabs/TabBarMixin.js index 93d6421c3..f70010914 100644 --- a/components/tabs/TabBarMixin.js +++ b/components/tabs/TabBarMixin.js @@ -21,14 +21,16 @@ export default { panels: Array, }, methods: { - getTabs () { + getTabs (h) { const { panels: children, activeKey, prefixCls } = this const rst = [] children.forEach((child) => { if (!child) { return } - const key = child.pKey + // componentOptions.propsData中获取的值disabled没有根据类型初始化, 会出现空字符串 + child.disabled = child.disabled === '' || child.disabled + const key = child.tabKey let cls = activeKey === key ? `${prefixCls}-tab-active` : '' cls += ` ${prefixCls}-tab` if (child.disabled) { @@ -52,7 +54,7 @@ export default { onClick={onClick} ref={activeKey === key ? 'activeTab' : undefined} > - {child.tab} + {typeof child.tab === 'function' ? child.tab(h, key) : child.tab} ) }) @@ -71,7 +73,7 @@ export default { let children = contents if ($slots.default) { children = [ -