效果截图:
代码展示:
<div class="tabbar">
<!-- 选项卡下面的小条 -->
<div class="tab-active active" :style="{ left: activeTab * 150 + 'px'}">
<div class="tab-slide"></div>
</div>
//选项卡标题数据
<div v-for="(tab, i) in tabs" :key="i" class="tab" @click="activeTab = i">
<text :class="['tab-title',activeTab==i?'tab-checked':'']">{{tab.title}}</text>
</div>
</div>
//选项卡内容
<slider class="tab-panels" :index="activeTab" @change="changeTab" infinite=false>
//选项卡对应的轮播图页面
<div class="tab-frame" v-for="(panel, pi) in tabs" :key="pi">
//对应页面的内容,可以自己自定义
<div v-for="(name,index) in panel.cate" :key="index" @click="selectTag(index,name)">
<text :class="[selectCate==index?'tab-content-checked':'tab-content']">{{name}}</text>
<image v-if="selectCate==index" class="tab-image-checked" src="https://w.bangbangce.com/static/wechat/Assets/Images/Public/bot_right.png"></image>
</div>
</div>
</slider>
样式代码:
.tabbar{
flex-direction: row;
}
.tab-active{
height: 100px;
width: 150px;
justify-content:flex-end ;
align-items: center;
}
.tab-slide{
height: 5px;
width: 50px;
border-radius: 10px;
background-color: #01b2b6;
}
.tab{
height: 120px;
width: 150px;
justify-content: center;
align-items: center;
}
.active {
position: absolute;
top: 0;
left: 0;
transition: left 0.2s ease-in-out;
}
.tab-title{
font-size: 30px;
}
.tab-checked{
color: #01b2b6;
}
.tab-panels {
position: relative;
width: 700px;
flex: 1;
transition: left 0.2s ease-in-out;
margin-right: 10px;
margin-left: 10px;
}
.tab-frame{
flex-direction: row;
flex-wrap: wrap;
}
.tab-content{
font-size: 35px;
color: #ffffff;
background-color: #01b2b6;
border-color: #01b2b6;
border-width: 3px;
border-radius: 10px;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 15px;
padding-right: 15px;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
margin-top: 10px;
}
.tab-content-checked{
font-size: 35px;
color: #01b2b6;
border-color: #01b2b6;
border-width: 3px;
border-radius: 10px;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 15px;
padding-right: 15px;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
margin-top: 10px;
}
.tab-image-checked{
width: 30px;
height: 30px;
border-bottom-right-radius: 5px;
position: absolute;
right: 13px;
bottom: 13px;
}
数据格式(可以自己随便定义):
tabs:[
{"title":"预测","cate":["随便","自定义"]},
{"title":"大运","cate":["很好","不错",""]}
],
完结撒花~