微信小程序之顶部普通选项卡(非swiper)

背景:前段时间写了一个抢红包小程序,里面涉及到了顶部选项卡,把它抽了出来。

效果图:


下面直接上代码:

wxml:

  <view class="navbar">
    <text wx:for="{{navbar}}" data-index="{{index}}" 
    class="item {{currentIndex==index?'active':''}}"
    bindtap="navbarTab" wx:key="unique">{{item}}</text>
  </view>
  <view hidden="{{currentIndex!==0}}">
    
  </view>
  <view hidden="{{currentIndex!==1}}">
    
  </view>


wxss:

.navbar{
  display: flex;
  width: 100%;
  flex-direction: row;
  line-height: 80rpx;
  position: fixed;
  top: 0;
}
.navbar .item{
  flex: auto;
  font-size: 30rpx;
  text-align: center;
  background: #fff;
  font-weight: bold;
}
.navbar .item.active{
  color: #36DB2C;
  position: relative;
}
.navbar .item.active::after{
  content: "";
  display: block;
  position: absolute;
  height: 4rpx;
  bottom: 0;
  left: 0;
  right: 0;
  background: #36DB2C;
}

js:

    data: {
        navbar: ["我发出的", "我收到的"],
        currentIndex: 0,//tabbar索引
    },
    navbarTab: function (e) {
        this.setData({
            currentIndex: e.currentTarget.dataset.index
        });
    },

以上是实现过程基本代码,省去了中间内容的代码。顶部个数是循环出来的,可以根据自己的实际需求设置。


附:swiper顶部选项卡链接


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值