微信小程序选项卡切换(滑动切换,点击切换)

效果如下:可点击切换,滑动切换



代码如下
这个可以在项目用

index.wxml

html 复制代码
<view class='topTabSwiper'>
    <view class='tab  {{currentData == 0 ? "tabBorer" : ""}}'  data-current = "0" bindtap='checkCurrent'>选项一</view>
    <view class='tab  {{currentData == 1 ? "tabBorer" : ""}}'  data-current = "1" bindtap='checkCurrent'>选项二</view>
</view>
<swiper current="{{currentData}}" class='swiper' style="height:600px;" duration="300" bindchange="bindchange">
  <swiper-item><view class='swiper_con'>TAB1</view></swiper-item> 
  <swiper-item><view class='swiper_con'>TAB2</view></swiper-item>
</swiper>

index.wxss

css 复制代码
.tab {
  
  width: 50%;
  text-align: center;
  padding: 10rpx 0;
}

.topTabSwiper {
  display: flex;
  justify-content: space-between;
}
.tabBorer {
  border-bottom: 1px solid #f00;
  color: #f00;
}

.swiper {
  width: 100%;
}

.swiper_con {
  text-align: center;
  width: 100%;
  height: 100%;
  padding: 80rpx 0;
}

index.js

js 复制代码
//获取当前滑块的index
  bindchange:function(e){
    const that  = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换,滑块index赋值
  checkCurrent:function(e){
    const that = this;

    if (that.data.currentData === e.target.dataset.current){
        return false;
    }else{

      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
相关推荐
橘 日向2 小时前
uniApp开发微信小程序-连接蓝牙连接打印机上岸!
微信小程序·uni-app·notepad++
code袁3 小时前
基于微信小程序的志愿服务系统的设计与实现
微信小程序·小程序·notepad++·课程设计·小程序开发·志愿服务小程序
m0_728647083 小时前
微信小程序开发:废品回收小程序-功能清单
java·小程序·小程序开发·废品回收小程序·微信小程序开发
2401_897930066 小时前
微信小程序运行机制详解
微信小程序·小程序
源码师傅7 小时前
深度解读分销小程序商城源码系统:从搭建到运营的关键指南
小程序·商城小程序源码·分销商城小程序源码
『 时光荏苒 』16 小时前
微信小程序实时日志记录-接口监控
微信小程序·小程序·微信小程序日志·日志抓取
老李不敲代码16 小时前
榕壹云外卖跑腿系统:基于Spring Boot+MySQL+UniApp的智慧生活服务平台
spring boot·mysql·微信小程序·uni-app·软件需求
社会底层无业大学生18 小时前
微信小程序跳
微信小程序·小程序·notepad++
ace_TiAmo20 小时前
React8+taro开发微信小程序,实现lottie动画
微信小程序·小程序·react·taro