index.js
1.5 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
import { VantComponent } from '../common/component';
VantComponent({
relation: {
name: 'tabbar-item',
type: 'descendant',
linked: function linked(target) {
var _this = this;
this.data.items.push(target);
setTimeout(function () {
_this.setActiveItem();
});
},
unlinked: function unlinked(target) {
var _this2 = this;
this.data.items = this.data.items.filter(function (item) {
return item !== target;
});
setTimeout(function () {
_this2.setActiveItem();
});
}
},
props: {
active: Number,
fixed: {
type: Boolean,
value: true
},
zIndex: {
type: Number,
value: 1
}
},
data: {
items: [],
currentActive: -1
},
watch: {
active: function active(_active) {
this.setData({
currentActive: _active
});
this.setActiveItem();
}
},
created: function created() {
this.setData({
currentActive: this.data.active
});
},
methods: {
setActiveItem: function setActiveItem() {
var _this3 = this;
this.data.items.forEach(function (item, index) {
item.setActive(index === _this3.data.currentActive);
});
},
onChange: function onChange(child) {
var active = this.data.items.indexOf(child);
if (active !== this.data.currentActive && active !== -1) {
this.$emit('change', active);
this.setData({
currentActive: active
});
this.setActiveItem();
}
}
}
});