forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (62 loc) · 1.49 KB
/
index.js
File metadata and controls
75 lines (62 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
const [createComponent, bem] = createNamespace('tab');
export default createComponent({
mixins: [ChildrenMixin('vanTabs')],
props: {
name: [Number, String],
title: String,
disabled: Boolean
},
data() {
return {
inited: false
};
},
computed: {
computedName() {
return this.name || this.index;
},
isActive() {
return this.computedName === this.parent.currentName;
}
},
watch: {
// eslint-disable-next-line object-shorthand
'parent.currentIndex'() {
this.inited = this.inited || this.isActive;
},
title() {
this.parent.setLine();
}
},
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(<div ref="title">{slots('title')}</div>);
}
if (this.parent.animated) {
return (
<div
role="tabpanel"
aria-hidden={!isActive}
class={bem('pane-wrapper', { inactive: !isActive })}
>
<div class={bem('pane')}>{Content}</div>
</div>
);
}
return (
<div vShow={isActive} role="tabpanel" class={bem('pane')}>
{Content}
</div>
);
}
});