竖版的tab,点击切换页面,代码如下:
wxml:
<view class="swiper-tab">
<view class="swiper-tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="clickTab"><text>最热</text></view>
<view class="swiper-tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="clickTab"><text>最新</text></view>
</view>
<view class = "{{currentTab == 0 ? 'show':'hidden'}}" >
<scroll-view>
</scroll-view>
</view>
<view class = "{{currentTab == 1 ? 'show':'hidden'}}" >
<scroll-view>
</scroll-view>
</view>
js:
//点击切换
clickTab: function (e) {
var that = this;
if (this.data.currentTab === e.target.dataset.current) {
return false;
} else {
that.setData({
currentTab: e.target.dataset.current,
})
}
}
css:
/* swiper-tab */
.about_page{
margin: 0 10px;
}
.swiper-tab{
width: 100%;
border-top: 2rpx solid #d0cece;
text-align: center;
/* height: 88rpx; */
/* line-height: 38rpx; */
padding-top: 10px;
display: flex;
flex-flow: row;
justify-content: space-between;
color: #ccc;
font-size: 16px;
}
.swiper-tab-item{
width: 50%;
color:#4e4e51;
}
.swiper-tab-item text{
border-bottom: 3rpx solid #d0cece;
padding-bottom: 4rpx;
}
.active text{
border-bottom: 3rpx solid #e64340;
}
.active{
color:#e64340;
font-size: 16px;
font-weight: 350;
}
.juzhong{
margin: 0 auto;
}
.domain{
background-color: #fff;
height: 100%;
margin:0 10px;
}
.show{
display: block;
}
.hidden{
display: none;
}
功能可以实现,但刚一进去的页面总是空白,想把“最热”部分设为默认。
然后尝试在js里面的data加了如下代码:
data: {
currentTab: 0
},
实现的效果: