需求:顶部导航栏
wxml:
<!--导航条--> <view class="navbar"> <text wx:for="pw_navbar" data-idx="pw_index" class="item pw_currenttab==index ? 'active' : ''" wx:key="unique" bindtap="navbartap">pw_item</text> </view> <!--首页--> <view hidden="pw_currenttab!==0"> tab_01 </view> <!--搜索--> <view hidden="pw_currenttab!==1"> tab_02 </view> <!--我--> <view hidden="pw_currenttab!==2"> tab_03 </view>
wxss:
page{ display: flex; flex-direction: column; height: 100%; } .navbar{ flex: none; display: flex; background: #fff; } .navbar .item{ position: relative; flex: auto; text-align: center; line-height: 80rpx; } .navbar .item.active{ color: #ffcc00; } .navbar .item.active:after{ content: ""; display: block; position: absolute; bottom: 0; left: 0; right: 0; height: 4rpx; background: #ffcc00; }
js:
var app = getapp() page({ data: { navbar: ['首页', '搜索', '我'], currenttab: 0 }, navbartap: function(e){ this.setdata({ currenttab: e.currenttarget.dataset.idx }) } })
以上就是小程序中顶部导航栏示例代码的详细内容。
