小程序实现tab标签页
更新时间:2020年11月15日 20:49 点击:2143
本文实例为大家分享了小程序实现tab标签页的具体代码,供大家参考,具体内容如下
页面效果:
HTML:
<view wx:if="{{userType==0}}" style="height:100%"> <view class="tab_box" style="width: 100%"> <view class="tabs_v"> <block wx:for="{{tabs}}" wx:for-item="item" wx:key="index"> <view class="tab_v {{index<1?'tab_nature':'tab_course'}}" bindtap='changeCurrentTab_' data-index='{{index}}' data-current='{{index}}'> <text class="tab_txt {{currentTab==index? 'tab_v_active' : ''}}">{{item.label}}</text> </view> </block> </view> </view> <!-- tab 容器 --> <view class="tabWrap"> <swiper class="" current="{{currentTab}}" duration="300" bindchange="swiperTab" style="width:100%;height:100%;"> <!-- 页面1 --> <block> <swiper-item style="width:100%;height:100%;"> <view class="" style="width:100%;height:100%;"> <scroll-view style="width:100%;height:100%;" scroll-y="true" bindscrolltolower='scrollToLower' bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'> <view style="width:100%;height:auto;"> 页面1 </view> </scroll-view> </view> </swiper-item> </block> <!-- 页面2 --> <block> <swiper-item style="width:100%;height:100%;"> <view class="" style="width:100%;height:100%;"> <scroll-view style="width:100%;height:100%;" scroll-y="true" bindscrolltolower='scrollToLower' bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'> <view style="width:100%;height:auto;"> 页面2 </view> </scroll-view> </view> </swiper-item> </block> </swiper> </view> </view>
CSS:
/* tab */ .tab_box{ height: 50px; display: flex; flex-direction: row; background-color: #fff; border-bottom: 1px solid #E5E5E5; margin-bottom: 15px; } .tabs_v{ width: 100%; display: flex; flex-direction: row; justify-content: space-between; align-items: center; } .tab_v{ width: 50%; text-align: center; } .tab_txt{ border-bottom: 2px solid transparent; padding-bottom: 14px; color: #999999; } .tab_v_active{ border-bottom: 2px solid #00C6AC; color: #00C6AC; font-weight: bold; } /* 容器 */ .tabWrap{ width: 100%; height: calc(100% - 67px); position: relative; border-bottom: 1px solid #e6e6e6; }
JS:
Page({ /** * 页面的初始数据 */ data: { tabs: [ {label:'访客', index: 0}, {label:'工作人员', index: 1} ], currentTab:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, // tab切换 changeCurrentTab_(e){ let that = this if (that.data.currentTab === e.currentTarget.dataset.current){ return false }else{ that.setData({ currentTab: e.currentTarget.dataset.current }) } }, //滑动切换 swiperTab: function (e) { var that = this; that.setData({ currentTab: e.detail.current }); } })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。
相关文章
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 这篇文章主要介绍了Python爬取微信小程序通用方法代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
- 这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
- 这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25
- 本文主要介绍了手把手教你uniapp和小程序分包,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-02
- 这篇文章主要为大家详细介绍了微信小程序实现canvas分享朋友圈海报,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21
- 这篇文章主要介绍了微信小程序 页面跳转传递值几种方法详解的相关资料,需要的朋友可以参考下...2017-01-16
- 这篇文章主要为大家详细介绍了微信小程序实现选择地址省市区三级联动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21
- 这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
- 这篇文章主要介绍了uniapp,微信小程序中使用 MQTT的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-07-11
- 这篇文章主要介绍了微信小程序自定义底部弹出框动画,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-16
- 这篇文章主要介绍了微信小程序 通过控制CSS实现view隐藏与显示的相关资料,需要的朋友可以参考下...2017-05-27
- 这篇文章主要介绍了微信小程序 富文本转文本实例详解的相关资料,需要的朋友可以参考下...2016-10-25
- 这篇文章主要为大家详细介绍了微信小程序入门之绘制时钟,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-10-23