• 微信小程序开发笔记(六)--实现tab选项卡


    wxml:

    <!-- pages/index/index.wxml -->
    <!--导航菜单-->
    <view class="navbar">
        <!--循环-->
        <view wx:for="{{navbar}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" bindtap="navbarTap">
            <view class="notice" wx:if="{{count[index]>0}}">{{count[index]}}</view>
            <text>{{item}}</text>
        </view>
    </view>
    
    <!--全部-->
    <view hidden="{{currentTab !== 0}}">我是全部</view>
    
    <!--支出-->
    <view hidden="{{currentTab !== 1}}">我是支出</view>
    
    <!--收入-->
    <view hidden="{{currentTab !== 2}}">我是收入</view>
    
    <!--其他-->
    <view hidden="{{currentTab !== 3}}">我是其他</view>

    js:

    // pages/index/index.js
    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        navbar: ['全部', '支出', '收入', '其他'],
        count: [5, 2, 3, 0], //记录不同状态记录的数量
        currentTab: 0,
      },
    
      //响应点击导航栏
      navbarTap: function (e) {
        var that = this;
        that.setData({
          currentTab: e.currentTarget.dataset.idx
        })
      },
    
    })

    wxss:

    /* pages/index/index.wxss */
    /*圆点数字标注*/
    .notice {
      width: 25rpx;
      height: 25rpx;
      color: #fff;
      text-align: center;
      background-color: #1DB1CF;
      border-radius: 50%;
      position: absolute;
      float: left;
      top: 5rpx;
      font-size: 20rpx;
      right: 30rpx;
      line-height: 25rpx;
    }
    
    /*顶部导航样式*/
    .navbar {
      flex: none;
      display: flex;
      background: #fff;
    }
    
    .navbar .item {
      position: relative;
      flex: auto;
      text-align: center;
      line-height: 80rpx;
      font-size: 30rpx;
      color: #666666;
    }
    
    .navbar .active {
      font-size: 40rpx;
      color: #1DB1CF;
    }
    
    .navbar .active:after {
      content: "";
      display: block;
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      height: 4rpx;
      background: #1DB1CF;
    }
    一辈子很短,努力的做好两件事就好;第一件事是热爱生活,好好的去爱身边的人;第二件事是努力学习,在工作中取得不一样的成绩,实现自己的价值,而不是仅仅为了赚钱。
  • 相关阅读:
    activity启动模式
    Android自定义view:折线图(附带动画效果)
    支付宝开发接口 Multiple dex files define Lcom/ta/utdid2/device/UTDevice
    android 开发中应用到的单例模式
    新浪微博分享错误代码 10014
    android Model与View解耦的一个简单方式
    android studio 新建项目导入到Coding远程仓库git
    一起学习MVC(2)数据库设计
    ASP.NET MVC :MVC页面验证与授权
    ASP.net:水晶报表的5种表格设计模式
  • 原文地址:https://www.cnblogs.com/antao/p/12650593.html
Copyright © 2020-2023  润新知