-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
/
index.js
95 lines (80 loc) · 1.98 KB
/
index.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
import { routeProps } from '../utils/router';
const [createComponent, bem] = createNamespace('tab');
export default createComponent({
mixins: [ChildrenMixin('vanTabs')],
props: {
...routeProps,
dot: Boolean,
name: [Number, String],
// @deprecated
info: [Number, String],
badge: [Number, String],
title: String,
titleStyle: null,
titleClass: null,
disabled: Boolean,
},
data() {
return {
inited: false,
};
},
computed: {
computedName() {
return this.name ?? this.index;
},
isActive() {
const active = this.computedName === this.parent.currentName;
if (active) {
this.inited = true;
}
return active;
},
},
watch: {
title() {
this.parent.setLine();
this.parent.scrollIntoView();
},
inited(val) {
if (this.parent.lazyRender && val) {
this.$nextTick(() => {
this.parent.$emit('rendered', this.computedName, this.title);
});
}
},
},
render(h) {
const { slots, parent, isActive } = this;
const slotContent = slots();
if (process.env.NODE_ENV === 'development' && this.info) {
console.warn(
'[Vant] Tab: "info" prop is deprecated, use "badge" prop instead.'
);
}
if (!slotContent && !parent.animated) {
return;
}
const show = parent.scrollspy || isActive;
const shouldRender = this.inited || parent.scrollspy || !parent.lazyRender;
const Content = shouldRender ? slotContent : h();
if (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={show} role="tabpanel" class={bem('pane')}>
{Content}
</div>
);
},
});