diff --git a/src/tab/index.js b/src/tab/index.js index 2a7dedc6d..2b3852d83 100644 --- a/src/tab/index.js +++ b/src/tab/index.js @@ -41,20 +41,10 @@ export default createComponent({ } }, - mounted() { - if (this.slots('title')) { - this.parent.renderTitle(this.$refs.title, this.index); - } - }, - render(h) { const { slots, isActive } = this; const shouldRender = this.inited || !this.parent.lazyRender; - const Content = [shouldRender ? slots() : h()]; - - if (slots('title')) { - Content.push(
{slots('title')}
); - } + const Content = shouldRender ? slots() : h(); if (this.parent.animated) { return ( diff --git a/src/tab/test/__snapshots__/demo.spec.js.snap b/src/tab/test/__snapshots__/demo.spec.js.snap index 57720ab15..00cf78c7b 100644 --- a/src/tab/test/__snapshots__/demo.spec.js.snap +++ b/src/tab/test/__snapshots__/demo.spec.js.snap @@ -194,10 +194,10 @@ exports[`renders demo correctly 1`] = `
- - + +
diff --git a/src/tabs/Title.js b/src/tabs/Title.js index 5b8b103ea..2b3576991 100644 --- a/src/tabs/Title.js +++ b/src/tabs/Title.js @@ -1,8 +1,8 @@ import { createNamespace } from '../utils'; -const bem = createNamespace('tab')[1]; +const [createComponent, bem] = createNamespace('tab'); -export default { +export default createComponent({ props: { type: String, color: String, @@ -51,12 +51,6 @@ export default { methods: { onClick() { this.$emit('click'); - }, - - renderTitle(el) { - const { title } = this.$refs; - title.innerHTML = ''; - title.appendChild(el); } }, @@ -73,10 +67,10 @@ export default { style={this.style} onClick={this.onClick} > - - {this.title} + + {this.slots() || this.title}
); } -}; +}); diff --git a/src/tabs/index.js b/src/tabs/index.js index dc7748af8..bf837cf5c 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -203,7 +203,11 @@ export default createComponent({ this.$emit('input', this.currentName); if (shouldEmitChange) { - this.$emit('change', this.currentName, this.children[currentIndex].title); + this.$emit( + 'change', + this.currentName, + this.children[currentIndex].title + ); } } }, @@ -246,13 +250,6 @@ export default createComponent({ scrollLeftTo(nav, to, immediate ? 0 : this.duration); }, - // render title slot of child tab - renderTitle(el, index) { - this.$nextTick(() => { - this.$refs.titles[index].renderTitle(el); - }); - }, - onScroll(params) { this.stickyFixed = params.isFixed; this.$emit('scroll', params); @@ -276,6 +273,9 @@ export default createComponent({ activeColor={this.titleActiveColor} inactiveColor={this.titleInactiveColor} swipeThreshold={this.swipeThreshold} + scopedSlots={{ + default: () => item.slots('title') + }} onClick={() => { this.onClick(index); route(item.$router, item); @@ -291,10 +291,17 @@ export default createComponent({ { [BORDER_TOP_BOTTOM]: type === 'line' && this.border } ]} > -
+
{this.slots('nav-left')} {Nav} - {type === 'line' &&
} + {type === 'line' && ( +
+ )} {this.slots('nav-right')}