Tab.vue
1.54 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<template>
<div :class="['TAB',{'sticky':sticky}]">
<van-tabs
v-model="tabIndex"
color="#3975C6"
title-inactive-color="#BBB"
title-active-color="#3975C6"
@click="click"
:key="updata"
v-bind="$attrs"
>
<template v-for="(i,index) in data">
<van-tab
:key="index"
:title-class="titleClass"
>
<template #title>
{{i}}
</template>
</van-tab>
</template>
</van-tabs>
</div>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'Tab',
props: {
list: {
type: Array,
default: () => {
return []
}
},
sticky: Boolean,
index: {
type: Number,
default: 0
},
updata: {
type: Number,
default: new Date().getTime()
},
titleClass: String
},
data () {
return {
tabIndex: this.index,
data: this.list
}
},
watch: {
'index' (n) {
this.tabIndex = n
},
'updata' (n) {
this.data = this.list
}
},
mounted () {
this.data = this.list || []
},
methods: {
click (tabIndex) {
this.tabIndex = tabIndex
this.$emit('change', tabIndex)
}
}
}
</script>
<style lang='scss'>
.TAB {
position: relative;
}
.sticky {
position: sticky;
top: 0;
z-index: 99;
}
.van-tabs__wrap {
height: 50px !important;
}
.van-tab__text {
transition: all 0.25s;
}
.van-tab--active {
.van-tab__text {
transform: scale(1.14) !important;
transform-origin: center;
}
}
</style>