• 小程序tab切换代码


    <!--index.wxml-->
    <view class="container">
      <view class="navtap" >
        <a data-current="{{setting.current.key}}" bindtap="clickcurrent" style="color:{{currentSelect.key == 'current'?mainColor:oldcolor}};">
          <text>本期试用</text>
          <text class="activeline" style="background-color:{{currentSelect.key == 'current'?mainColor:whiteColor}};"></text>
        </a>
        <a data-current="{{setting.trailer.key}}" bindtap="clickcurrent" style="color:{{currentSelect.key == 'trailer'?mainColor:oldcolor}};">
          <text>即将上线</text>
          <text class="activeline" style="background-color:{{currentSelect.key == 'trailer'?mainColor:whiteColor}};"></text>
        </a>
        <a data-current="{{setting.report.key}}" bindtap="clickcurrent" style="color:{{currentSelect.key == 'report'?mainColor:oldcolor}};">
          <text>试用报告</text>
          <text class="activeline" style="background-color:{{currentSelect.key == 'report'?mainColor:whiteColor}};"></text>
        </a>
        <a data-current="{{setting.mytry.key}}" bindtap="clickcurrent" style="color:{{currentSelect.key == 'mytry'?mainColor:oldcolor}};">
          <text>我的试用</text>
          <text class="activeline" style="background-color:{{currentSelect.key == 'mytry'?mainColor:whiteColor}};"></text>
        </a>
      </view>
      <block wx:if="{{currentSelect.key == 'current'}}">
        111
      </block>
      <block wx:if="{{currentSelect.key == 'trailer'}}">
        222
      </block>
      <block wx:if="{{currentSelect.key == 'report'}}">
        333
      </block>
      <block wx:if="{{currentSelect.key == 'mytry'}}">
        444
      </block>
    </view>

    js

    //index.js
    //获取应用实例
    const app = getApp()
    
    Page({
      data: {
        motto: '首页',
        setting: {
          current: {
            key: "current",
          },
          trailer: {
            key: "trailer"
          },
          report: {
            key: "report"
          },
          mytry: {
            key: "mytry"
          }
        },
        mainColor: '#91d8d2',
        oldcolor: 'grey'
      },
      currentSelect: {},
      onLoad: function () {
         this.setData({
           'currentSelect.key': 'current'
         })
      },
      clickcurrent: function (event) {
        var that = this
        that.setData({
          'currentSelect.key':event.currentTarget.dataset.current
        })  
      } 
    })

    wxss

    /**index.wxss**/
    
    .navtap{
        100%;
        height:40px;
        text-align:center;
        display:flex;
        font-size:15px;
        color:#838995;
        background-color:#fff;
    
    }
    
    .navtap a{
        flex:1;
        color:#838995;
        line-height:38px;
    }
    
    .activeline{
        26px;
        height:2px;
        background-color:#fff;
        display:block;
        margin:0 auto;
    }
    .navtap a {
        flex:1;
        color:#838995;
        line-height:38px;
    }
  • 相关阅读:
    软件 = 程序 + 软件工程(构建之法读书笔记一)
    网站系统开发需要掌握的技术
    C++迪杰斯特拉算法求最短路径
    strcpy函数在VS2015无法使用的问题
    C++哈夫曼树编码和译码的实现
    java学习中一些疑惑解答(2)
    凯撒加密、解密算法
    利用DOS批处理实现定时关机操作
    C及C++中typedef的简单使用指南
    java学习中的一些疑惑解答
  • 原文地址:https://www.cnblogs.com/antyhouse/p/9360653.html
Copyright © 2020-2023  润新知