tabs.vue
1.9 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
<template>
<div>
<div class="tabs">
<div class="display-flex-between">
<div
class="tabsitem"
@click="chooseTab(index)"
v-bind:style="{width:itemwidth+'px'}"
:class="active===index?'activeclass':''"
v-for="(item,index) in tabs"
:key="index">{{item}}</div>
</div>
<div class="activeclassline" v-bind:style="{left:left+'px'}"></div>
</div>
</div>
</template>
<script>
export default {
name: 'tabs',
props: {
tabs: {
type: Array
},
active: {
type: Number,
default: 0
}
},
data () {
return {
left: 20,
itemwidth: ''
}
},
created () {
this.itemwidth = document.documentElement.clientWidth / this.tabs.length
this.left = (this.active * this.itemwidth) + this.itemwidth / 2
},
watch: {
active: function () {
this.left = (this.active * this.itemwidth) + this.itemwidth / 2
}
},
methods: {
chooseTab (index) {
this.left = (index * this.itemwidth) + this.itemwidth / 2
this.$emit('choose', index)
}
}
}
</script>
<style scoped lang="scss">
.tabs{
width: 100%;
height: auto;
padding:0.24rem 0;
box-sizing: border-box;
font-size: 0.28rem;
color: rgba(150,151,153,1);
background-color: #fff;
position: relative;
}
.tabsitem{
text-align: center;
}
.activeclass{
color: rgba(50,50,51,1);
font-weight: 600;
}
.activeclassline{
content:'';
position: absolute;
top: 95%;
transform: translate(-50%,0);
width: 0.24rem;
height: 0.06rem;
opacity: 1;
background: linear-gradient(180.25deg, rgba(37,202.68,255,1) 0%, rgba(67.52,37,255,1) 100%);
transition: all 0.15s ease-in;
}
</style>