效果图:
wxml:
<view>
<!--导航条-->
<view class="navbar">
<text wx:for="{{navbar}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : 'activex'}}" wx:key="unique" bindtap="navbar">{{item}}</text>
</view>
<!--水果-->
<view hidden="{{currentTab!==0}}">
<!-- 内容 -->
<view class="zj">
<view class="text">
<text>111111</text>
</view>
</view>
</view>
<!--蔬菜-->
<view hidden="{{currentTab!==1}}">
<!-- 内容 -->
<view class="zj">
<view class="text">
<text>222222</text>
</view>
</view>
</view>
</view>
wxss:
.navbar{
flex: none;
display: flex;
background: #fff;
border-bottom: 1rpx #07C160;
}
.navbar .item{
position: relative;
flex: auto;
text-align: center;
line-height: 80rpx;
font-size: 32rpx;
}
/*选中后字体颜色*/
.navbar .item.active{
color: #07C160;
}
/*选中后下划线颜色*/
.navbar .item.active:after{
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 7rpx;
background: #07C160;
}
js:
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
navbar: ['水果', '蔬菜'],
currentTab: 0
},
//点击选中方法
navbar: function(e){
this.setData({
currentTab: e.currentTarget.dataset.idx
})
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/98682.html