简单的 微信小程序 选项卡 tab 支持左右滑动

微信小程序 选项卡 tab 可左右滑动,可点击选择

小程序模板

<view class="box">
  <view class="topTabSwiper">
    <view wx:for="{{tabs}}" wx:key="tab_id" class="tab {{currentData == index ?'tabBorer':''}} " data-current="{{index}}" wx:item="item" bindtap="checkCurrent">{{item.tab_name}}</view>
  </view>
  <swiper current="{{currentData}}" class='swiper' duration="300" bindchange="bindchange">
    <swiper-item wx:for="{{list}}" wx:key="customer_mobile" wx:item="item">
    {{item.name}}
    </swiper-item>
  </swiper>
</view>

小程序css

.box{ width: 750rpx; display: block;}
.tab {
  width: 50%;
  display: block;
  height: 60rpx; line-height: 60rpx;
  text-align: center;
}

.topTabSwiper {width: 750rpx; display: flex; justify-content: space-between;
}
.topTabSwiper:after {
  content: "";
  clear: both;
  display: block;
}
.tabBorer {
  border-bottom: 1px solid #f00;
  color: #f00;
} 
.swiper {
  width: 100%;
  height: calc(100vh - 70rpx) ;
} 
.swiper_con {
  text-align: center;
  width: 100%;
  height: 100%;
  padding: 80rpx 0;
}

小程序javascript

// pages/cstab/cstab.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData : 0,
    tabs:[
      {tab_id:'1',tab_name:'导航1'},
      {tab_id:'2',tab_name:'导航2'},
      {tab_id:'3',tab_name:'导航3'},
    ],
    list:[
      {name:'我导航1对应的tab页'},
      {name:'我导航2对应的tab页'},
      {name:'我导航3对应的tab页'},
    ]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  bindchange:function(e){
    const that  = this;
    that.setData({
      currentData: e.detail.current
    })
},
checkCurrent:function(e){

      const that = this;
      if (that.data.currentData === e.target.dataset.current){
          return false;
      }else{
  
        that.setData({
          currentData: e.target.dataset.current
        })
      }
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

在这里插入图片描述

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

功能点分享

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值