一、效果图
二、代码
1、xml页面
<!-- 切换的tab栏 -->
<view class="tab-container">
<view
class="default {{type=='plan'? 'type-active':''}}"
bindtap="handleType"
data-type="plan"
>计划详情</view
>
<view
class="default {{type=='internship'? 'type-active': ''}}"
bindtap="handleType"
data-type="internship"
>实习任务</view
>
</view>
<!-- 计划详情 -->
<view wx:if="{{type=='plan'}}">
1
</view>
<!-- 实习任务 -->
<view wx:if="{{type=='internship'}}">
2
</view>
2、wxss
/* tab切换 */
.tab-container{
display: flex;
padding: 0 40rpx;
width:670rpx;
margin-top: 20rpx;
}
.default{
font-size: 28rpx;
font-weight: 500;
color: #626262;
margin-right: 56rpx;
}
.type-active{
color: #262626;
}
3、js
data: {
type:'plan',//控制tab切换
},
// 控制tab栏
handleType(event) {
const type = event.currentTarget.dataset.type;
this.setData({
type: type,
});
},