本篇文章为大家展示了在小程序开发中如何实现一个tab标签页,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
具体内容如下
页面效果:
HTML:
<view wx:if="{{userType==0}}" >
<view class="tab_box" >
<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" >
<!-- 页面1 -->
<block>
<swiper-item >
<view class="" >
<scroll-view scroll-y="true" bindscrolltolower='scrollToLower'
bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'>
<view >
页面1
</view>
</scroll-view>
</view>
</swiper-item>
</block>
<!-- 页面2 -->
<block>
<swiper-item >
<view class="" >
<scroll-view scroll-y="true" bindscrolltolower='scrollToLower'
bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'>
<view >
页面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
});
}
})
上述内容就是在小程序开发中如何实现一个tab标签页,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。