小程序之 tab切換(選項卡)


好久沒有寫東西了   今天寫一個簡單的東西

小程序tab切換 (選項卡功能)

 

.wxml

<view class="swiper-tab">
  <view class="swiper-tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="clickTab">111</view>
  <view class="swiper-tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="clickTab">222</view>
</view>

<swiper current="{{currentTab}}" bindchange="swiperTab" style="height:{{swiperHeight}}rpx;">
  <swiper-item>
    <view class='ycy'>
      <text>111111</text>
    </view>
  </swiper-item>

  <swiper-item>
    <view class='ycy'>
      <text>222222</text>
    </view>
  </swiper-item>
</swiper>

 

.js

Page({
  data: {
    currentTab: 0,
  },
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
})

 

.wxss

.swiper-tab{
    width: 100%;
    border-bottom: 1rpx solid #eee;
    text-align: center;
    height: 90rpx;
    line-height: 90rpx;
    display: flex;
    flex-flow: row;
    font-size: 32rpx;
    justify-content: space-between;
}
.swiper-tab-item{
    width: 50%; 
    color:#434343;
}
.active{
  color:#F65959;
  border-bottom: 2rpx solid #F65959;
}
.ycy{
  width: 100%;
  display: flex;
  height: 95rpx;
  border-bottom: 1px solid #eee;
  position: relative;
}

 


免責聲明!

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



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