小程序--導航欄切換(tab切換)


1.展示

 

2.代碼片段

WXML
導航欄
<view class="swiper-tab">
    <view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">未完成</view>
    <view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">已完成</view>
</view>

內容
<swiper current="{{currentTab}}" class="swiper-box" duration="300" bindchange="bindChange">
    <swiper-item class="swiper-item">
        未完成內容
    </swiper-item>
    <swiper-item class="swiper-item">
        已完成內容
    </swiper-item>
</swiper>
JS
 data: {
    currentTab: 0
},
//  tab切換邏輯
     swichNav: function( e ) {
 
         var that = this;
 
         if( this.data.currentTab === e.target.dataset.current ) {
             return false;
         } else {
             that.setData( {
                 currentTab: e.target.dataset.current
             })
         }
     },
 
     bindChange: function( e ) {
 
         var that = this;
         that.setData( { currentTab: e.detail.current });
 
     },
WXSS
.swiper-tab {
  width: 100%;
  text-align: center;
  height: 100rpx;
  line-height: 100rpx;
  padding: 0 60rpx;
  margin-top: 20rpx;
  margin-bottom: 20rpx;
  background-color: rgb(255, 255, 255);
  display: flex;
  justify-content: space-around;
}

.swiper-tab-list {
  font-size: 30rpx;
  display: inline-block;
  width: 30%;
  color: #666666;
}

.on {
  color: #FDA53B;
  border-bottom: 5rpx solid #FDA53B;
}

.swiper-box {
  display: block;
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
  font-family: "蘋方-簡 常規體";
  height: 80vh;
}

.swiper-box .swiper-item {
  padding: 0 25rpx;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM