• 根据id来实现小程序tab切换,


    本例根据绑定id来实现tab切换,但本例仍有缺陷,用for循环数据,无法实现切换。如有大神能够有更好方法,欢迎留言更正

    WXML:

    <view class="tab"> 
      <view bindtap="tabs" class="{{tabArr.curHdIndex=='0'? 'active' : ''}}" id="0" data-id="0">tab-hd01</view> 
      <view bindtap="tabs" class="{{tabArr.curHdIndex=='1'? 'active' : ''}}" id="1" data-id="1">tab-hd02</view> 
      <view bindtap="tabs" class="{{tabArr.curHdIndex=='2'? 'active' : ''}}" id="2" data-id="2">tab-hd03</view> 
      <view bindtap="tabs" class="{{tabArr.curHdIndex=='3'? 'active' : ''}}" id="3" data-id="3">tab-hd04</view> 
    </view> 
     
    <view class="tabcon"> 
      <view class="{{tabArr.curBdIndex=='0'? 'active' : ''}}">tab-bd01111</view> 
      <view class="{{tabArr.curBdIndex=='1'? 'active' : ''}}">tab-bd02222</view> 
      <view class="{{tabArr.curBdIndex=='2'? 'active' : ''}}">tab-bd03333</view> 
      <view class="{{tabArr.curBdIndex=='3'? 'active' : ''}}">tab-bd04444</view> 
    </view>
    

    WXSS:

    .tab{
      display: flex;
      flex-direction:row; 
      height: 50px;
      line-height: 50px;
    
    }
    .tab view{
       25%;
      text-align: center;
    }
    .tab .active{
      display: inline-block;
      color: #188eee;
      border-bottom: 1px #188eee solid;
    }
    .tabcon view{
      display: none;
    }
    .tabcon .active{
      display: inline-block;
    }
    

    JS

    Page({
      data: {
        tabArr: {
          curHdIndex: 0,
          curBdIndex: 0,
        }
      },
      tabs: function (e) {
        var dataId = e.currentTarget.id;
        var obj = {};
        obj.curHdIndex = dataId;
        obj.curBdIndex = dataId;
        
        this.setData({
          tabArr: obj
        }); 
      }
    });
    

      

  • 相关阅读:
    linux mint 17编译android 2.3.1错误记录
    android字母索引实现ListView定位
    android实现emoji输入
    shell管道与重定向
    c3p0配置记录
    ubuntu13 eclipse菜单栏失效解决
    Proxy实现java动态代理
    ubuntu13启动屏幕亮度0解决方法
    cookie和session笔记
    linux mysql中文乱码解决
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/6993958.html
Copyright © 2020-2023  润新知