小程序tab实现页面切换

本文实例为大家分享了小程序tab实现页面切换的具体代码,供大家参考,具体内容如下

.wxml

<view class='title'>       <view class='titleSel' bindtap='titleClick' data-idx='0'>         <text>待接收(0)</text>         <hr class="{{0 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}}" />       </view>       <view class='titleSel' bindtap='titleClick' data-idx='1'>         <text>处理中(1)</text>         <hr class="{{1 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}} " />       </view>         <view class='titleSel' bindtap='titleClick' data-idx='2'>         <text>已完成(1)</text>         <hr class="{{2 == currentIndex ? 'headerLineSel' : 'headerLineUnsel'}} " />       </view>   </view>   <!--内容布局-->   <view class="colors">       <view class="colors1" wx:if="{{currentIndex==0}}">       {{currentIndex}}       </view>        <view class="colors2" wx:if="{{currentIndex==1}}">              {{currentIndex}}       </view>        <view class="colors3" wx:if="{{currentIndex==2}}">              {{currentIndex}}       </view> </view>

.wxss

page{   width: 100%;   height: 100%; } .container {   height: 100%;   min-height: 100%;   display: flex;   flex-direction: column;   box-sizing: border-box; } .title {   width: 100%;   height: 88rpx;   background: white;   display: flex;   align-items: center;   justify-content: space-around; } .titleSel {   width: 33%;   color: #5f6fee;   font-size: 32rpx;   display: flex;   flex-direction: column;   align-items: center; } .titleUnsel {   color: #858fab;   font-size: #858fab; } .headerLineSel {   background: #5f6fee;   height: 6rpx;   width: 40rpx;   position: relative;   margin-top: 10rpx; } .headerLineUnsel {   background: #fff;   height: 6rpx;   width: 40rpx;   position: relative;   margin-top: 10rpx; } .colors{   width: 100%;   height: 100%; } .colors1{   width: 100%;   height: 100%;   background-color: royalblue; } .colors2{   width: 100%;   height: 100%;   background-color: salmon; } .colors3{   width: 100%;   height: 100%;   background-color: seagreen; }

.js

data: {     currentIndex: 0,   },   //用户点击tab时调用   titleClick: function (e) {     let currentPageIndex =       this.setData({         //拿到当前索引并动态改变         currentIndex: e.currentTarget.dataset.idx       })       console.log(e.currentTarget.dataset.idx)   },

推荐阅读

    678元的索泰zt-h55d3-m1dh主板

    678元的索泰zt-h55d3-m1dh主板,,近日,索泰zt-h55d3-m1dh主板已经运到市场,这是基于英特尔H55芯片组。它支持LGA 1156接口的酷睿i系列处理器

    学习写字楼新选择6000元主流配置

    学习写字楼新选择6000元主流配置,,这种配置需要考虑双核心的办公和娱乐平台,充分考虑办公室的办公需求和娱乐需求,以约6000元的预算和cost-e

    金蝶专业版审核以前期间的单据

    金蝶专业版审核以前期间的单据,,1.之前会计是手工做账,现在是金蝶做账,需要什么资料入初始数据在金碟里把你手工帐的科目设置好,然后启用帐

    excel怎么用乘法函数

    excel怎么用乘法函数,乘法,函数,哪个,excel乘法函数怎么用?1、首先用鼠标选中要计算的单元格。2、然后选中单元格后点击左上方工具栏的fx公

    金蝶担保机构业务管理系统

    金蝶担保机构业务管理系统,,1.金蝶财务软件怎么使用?软件使用方法 使用需要先登陆到数据库,可只导出V3数据或只导出最新年度数据。功能介绍

    wps如何合并章节

    wps如何合并章节,WPS教程,1.WPS表格如何实现单元格合并?WPS 表格在新版本中增加了“合并单元格”系列按钮,同时配有下拉菜单和快捷键。新增