欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序的tab选项卡的实现效果

程序员文章站 2023-11-29 22:07:22
效果图,既可以点击切换,又可以滑动切换 .wxml

效果图,既可以点击切换,又可以滑动切换

微信小程序的tab选项卡的实现效果

.wxml

<!--pages/detail/detail.wxml-->
<view class="swiper-tab">
  <view class="swiper-tab-item {{currenttab==0?'active':''}}" data-current="0" bindtap="clicktab">全部</view>
  <view class="swiper-tab-item {{currenttab==1?'active':''}}" data-current="1" bindtap="clicktab">提现中</view>
  <view class="swiper-tab-item {{currenttab==2?'active':''}}" data-current="2" bindtap="clicktab">已提现</view>
</view>

<swiper current="{{currenttab}}" duration="300" bindchange="swipertab">
  <swiper-item ><view>全部</view></swiper-item>
  <swiper-item><view>提现中</view></swiper-item>
  <swiper-item><view>已提现</view></swiper-item>
</swiper>

.wxss

/* pages/detail/detail.wxss */
.swiper-tab{
  width: 100%;
  border-bottom: 2rpx solid #ccc;
  text-align: center;
  height: 88rpx;
  line-height: 88rpx;
  display: flex;
  flex-flow: row;
  justify-content: space-between;
}
.swiper-tab-item{
  width: 30%; 
  color:#434343;
}
.active{
  color:#f65959;
  border-bottom: 4rpx solid #f65959;
}
swiper{
 text-align: center;
}

.js

// pages/detail/detail.js
var app = getapp()
page({
 data: {
  currenttab: 0
 },
 onload: function (options) {
  // 页面初始化 options为页面跳转所带来的参数

 },
 //滑动切换
 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
   })
  }
 }
})

以上所述是小编给大家介绍的微信小程序的tab选项卡的实现效果详解整合,希望对大家有所帮助