小程序tab实现页面切换(二)

.wxml

  <view class='title'>
      <view class='titleSel' bindtap='titleClick' data-idx='0'>
        <text>待接收(0)</text>
        <hr class="{{0 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}}" />
      </view>
    
      <view class='titleSel' bindtap='titleClick' data-idx='1'>
        <text>处理中(1)</text>
        <hr class="{{1 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}} " />
      </view>

        <view class='titleSel' bindtap='titleClick' data-idx='2'>
        <text>已完成(1)</text>
        <hr class="{{2 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}} " />
      </view>
  </view>

  <!--内容布局-->
  <view class="colors">
      <view class="colors1" wx:if="{{currentIndex==0}}">
      {{currentIndex}}
      </view>
       <view class="colors2" wx:if="{{currentIndex==1}}">
             {{currentIndex}}
      </view>
       <view class="colors3" wx:if="{{currentIndex==2}}">
             {{currentIndex}}
      </view>
  </view>

.wxss

page{
  width: 100%;
  height: 100%;
}
.container {
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.title {
  width: 100%;
  height: 88rpx;
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.titleSel {
  width: 33%;
  color: #5f6fee;
  font-size: 32rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.titleUnsel {
  color: #858fab;
  font-size: #858fab;
}

.headerLineSel {
  background: #5f6fee;
  height: 6rpx;
  width: 40rpx;
  position: relative;
  margin-top: 10rpx;
}

.headerLineUnsel {
  background: #fff;
  height: 6rpx;
  width: 40rpx;
  position: relative;
  margin-top: 10rpx;
}


.colors{
  width: 100%;
  height: 100%;
}

.colors1{
  width: 100%;
  height: 100%;
  background-color: royalblue;
}
.colors2{
  width: 100%;
  height: 100%;
  background-color: salmon;
}
.colors3{
  width: 100%;
  height: 100%;
  background-color: seagreen;
}

.js

data: {
    currentIndex: 0,
   
  },
 
  //用户点击tab时调用
  titleClick: function (e) {
    let currentPageIndex =
      this.setData({
        //拿到当前索引并动态改变
        currentIndex: e.currentTarget.dataset.idx
      })

      console.log(e.currentTarget.dataset.idx)
  },

边学边记!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值