<text wx:for="pw_navbar" data-idx="pw_index " class="item pw_currentTab==index ? 'active' : ''" wx:key="uni"/> <text wx:for="pw_navbar" data-idx="pw_index " class="item pw_currentTab==index ? 'active' : ''" wx:key="uni">

Home  >  Article  >  WeChat Applet  >  Sample code for top navigation bar in mini program

Sample code for top navigation bar in mini program

巴扎黑
巴扎黑Original
2017-09-12 10:56:292294browse

微信小程序 开发之顶部导航栏

需求:顶部导航栏

wxml:

&lt;!--导航条--> 
&lt;view class="navbar"> 
 &lt;text wx:for="pw_navbar" data-idx="pw_index" class="item pw_currentTab==index ? &#39;active&#39; : &#39;&#39;" wx:key="unique" bindtap="navbarTap">pw_item&lt;/text> 
&lt;/view> 
 
&lt;!--首页--> 
&lt;view hidden="pw_currentTab!==0"> 
 tab_01 
&lt;/view> 
 
&lt;!--搜索--> 
&lt;view hidden="pw_currentTab!==1"> 
 tab_02 
&lt;/view> 
 
&lt;!--我--> 
&lt;view hidden="pw_currentTab!==2"> 
 tab_03 
&lt;/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: [&#39;首页&#39;, &#39;搜索&#39;, &#39;我&#39;], 
  currentTab: 0 
 }, 
 navbarTap: function(e){ 
  this.setData({ 
   currentTab: e.currentTarget.dataset.idx 
  }) 
 } 
})

The above is the detailed content of Sample code for top navigation bar in mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn