自定义组件Tab

#自定义组件

效果图

思路

代码

Html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<van-sticky>
<div class="switchBar">
<div class="checked">
<div
class="checkedLi"
v-for="(item, index) in helpIndex"
:key="index"
:class="{ active: index == isActive }"
@click="changeHelpIndex(index)">
{{ item.typeName }}
</div>
</div>
</div>
</van-sticky>

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
data() {
return {
helpIndex: [{
typeName: '特惠区',
type: 0,
}, {
typeName: '体验区',
type: 1,
}],
isActive: 0,
}
}

Css

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
.switchBar {
width: 100%;
overflow-x: scroll;
background: #f5f5f5;

.checked {
margin: 30px 30px 10px;
display: flex;
justify-content: flex-start;


.checkedLi {
position: relative;
white-space: nowrap;
width: 142px;
height: 44px;
text-align: center;

font-size: 28px;
font-family: PingFang SC;
font-weight: 500;
color: #999999;
line-height: 40px;
}

.active {

font-size: 32px;
font-family: PingFang SC;
font-weight: bold;
color: #000000;
line-height: 40px;

position: relative;
//width: 100px;
height: 56px;
text-align: center;
//border-bottom:2px solid #5A8BFF; //第一层下划线
//margin:63px auto 40px;
&::after {
content: "";
display: block;
position: absolute;
left: calc(50% - 23px);
bottom: 0;
margin-top: 20px;
width: 46px;
height: 10px;
border-radius: 5px;
background: linear-gradient(90deg, #FF7335, #FE3030);
box-shadow: 0px 2px 9px 0px rgba(254, 50, 48, 0.42);
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
}
}
}

https://codepen.io/hbisedm/pen/yLvXNaz


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!