uniapp 顶部选项卡 TopTabBar
在那里,只能自己手动实现
1. 项目结构
+ home + mine + TopBar + TopBarComponent + guanzhu.vue + tuijian.vue
2. 实现TopTab的静态UI界面
(1)顶部选项卡的布局 --- 当前为TopBar页面
<template>
<!-- 顶部选项卡 -->
<view class="tabs">
<view
class="uni-tab-item"
v-for="(tab,index) in tabBars"
:key="tab.id"
>
<text
class="uni-tab-item-title"
:class="{tabActive: tabIndex==tab.id}"
@tap="tarTap(tab)"
>
{
{tab.name}}
<span class="tab-item-title-line"></span>
</text>
</view>
</view>
</template>
<script>
export default {
name: "index-tabbar",
props:{
tabBars: Array,
tabIndex: String
},
data(){
return {
}
},
methods:{
tarTap(item){
this.$emit("TarTap",item)
}
}
}
</script>
<style>
.tabs{
display: flex;
flex: 1;
flex-direction: row;
overflow-x: scroll;
height: 100%;
}
.uni-tab-item{
width: 100%;
white-space: nowrap;
line-height: 100rpx;
height: 100rpx;
border-bottom: 1px solid #eee;
}
.uni-tab-item-title{
color: #969696;
font-weight: bold;
font-size: 38rpx;
width: 150rpx;
display: inline-block;
text-align: center;
color: #555;
}
.tabActive{
color: #343434;
}
.tabActive .tab-item-title-line{
display: block;
border-bottom: 4rpx solid #fede33;
border-top: 4rpx solid #fede33;
width: 86rpx;
margin: 0 auto;
border-radius: 40rpx;
margin-top: -10px;
background-color: #FEDE33;
box-sizing: border-box;
}
</style>
(2)在home界面导入 TopTab选项卡组件,为其添加数据
这样静态的选项卡就出现了
该技术点是,通过点击选项卡获取当前选项id名称,来显示对应组件
在Home界面,添加选项卡内容显示
