Tab.vue
1.26 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
<template>
<div class="tab">
<template v-for="(i,index) in data">
<div
@click="change(index)"
:class="['item' ,'text-center', {'active':index == tabIndex}]"
:key="index"
>{{i}}</div>
</template>
<div :class="['line',`type-${tabIndex}`]"></div>
</div>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'Tab',
props: {
data: {
type: Array,
default: () => {
return []
}
}
},
data () {
return {
tabIndex: 0
}
},
mounted () {
},
methods: {
change (tabIndex) {
this.tabIndex = tabIndex
this.$emit('change', tabIndex)
}
}
}
</script>
<style scoped lang='scss'>
.tab {
position: sticky;
top: 0;
z-index: 2;
display: grid;
grid-template-columns: repeat(2, 1fr);
background-color: #fff;
height: 44px;
.item {
color: #a9a9a9;
font-size: 14px;
transition: all 0.5s;
}
.active {
font-size: 16px;
color: #2c2c2c;
font-weight: 500;
}
.line {
position: absolute;
bottom: 0;
background: #5850ff;
border-radius: 2px;
height: 3px;
width: 40px;
transform: translateX(-50%);
transition: all 0.25s;
}
.type-0 {
left: 25%;
}
.type-1 {
left: 75%;
}
}
</style>