mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 10:44:59 +00:00
[improvement] Tabs: use relation mixin
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user