xml布局
<!--导航条--><view class="navbar"> //循环导航的名字 <text wx:for="{{navbar}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" wx:key="unique" bindtap="navbarTap">{{item}}</text></view> <!--首页--><view hidden="{{currentTab!==0}}"> tab_01</view> <!--搜索--><view hidden="{{currentTab!==1}}"> tab_02</view> <!--我--><view hidden="{{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;}//导航里点击之后字的大小、导航底下的样式(可以设置宽高width;height;)和颜色.navbar .item.active:after{ content: ""; display: block; position: absolute; bottom: 0; left: 0; right:香港vps 0; height: 4rpx; background: #FFCC00;}JS文件
var app = getApp()Page({ data: { navbar: ['首页', '搜索', '我'], currentTab: 0 /*初始显示的页面*/ }, //点击触发的事件 navbarTap: function(e){ this.setData({ currentTab: e.currentTarget.dataset.idx }) }}) 成果展示