• 微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)


    这里主要用到了swiper组件和三目运算,直接上代码, 样式只有三个class,简单粗暴,懒的小伙伴们可以直接拿来用,喜欢的点个支持

    <view>
      <view class="swiper-tab">
        <view class="bre swiper-tab-list {{tab==0 ? 'on' : ''}}" data-current="0" bindtap="tab_click">图文详情</view>
        <view class="swiper-tab-list {{tab==1 ? 'on' : ''}}" data-current="1" bindtap="tab_click">产品参数</view>
      </view>
      <swiper current="{{tab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="tab_slide">
        <swiper-item>
          图文详情
        </swiper-item>
     
        <swiper-item>
          产品参数
        </swiper-item>
      </swiper>
    </view>
    Page({
      data: {
        tab: 0
      },
      tab_slide: function (e) {//滑动切换tab 
        var that = this;
        that.setData({ tab: e.detail.current });
      },
      tab_click: function (e) {//点击tab切换
        var that = this;
        if (that.data.tab === e.target.dataset.current) {
          return false;
        } else {
          that.setData({
            tab: e.target.dataset.current
          })
        }
      },
    })
    .swiper-tab{  
        width: 100%;  
        border-bottom: 2rpx solid #eee;  
        text-align: center;  
        line-height: 80rpx;
        background: #fff;
        font-size: 14px;
    }  
    .on{ 
      color: #dd2727;  
      border-bottom: 5rpx solid #dd2727;
    }  
    .swiper-tab-list{  
      font-size: 29rpx;  
        display: inline-block;  
        width: 49.5%;  
        color: #333; 
    }

    原文链接:https://blog.csdn.net/qq_31383345/article/details/53453182

  • 相关阅读:
    进程间通信
    图形的保存与重绘
    mysql记录1
    文件操作
    多线程及聊天室程序
    健康是成功之本
    文档与串行化
    HTML网页制作基础
    Hook和数据库访问
    C++基础笔记1
  • 原文地址:https://www.cnblogs.com/Webzhoushifa/p/9574724.html
Copyright © 2020-2023  润新知