微信小程序自定义底部导航栏,切换不同页面显示不同tabbar

    在一个微信小程序中想要用到两种不同的tabbar样式,需要在app.js中自定义,在页面加载时进行调用。

比如一个小程序需要两个版本(用户版、商家版),并且能通过一个按钮在两个版本间进行切换,可能会用到这种方式。

    此处以两个页面(index,logs)显示两种tabbar样式为例,通过切换按钮进行切换。

    首先有一个模板文件:tabbar.wxml

<template name="tabBar">    
  <view class="tab-bar" style="color: {
  
  {tabBar.color}}; background: {
  
  {tarBar.backgroundColor}}; {
  
  {tabBar.position=='top'? 'top: 0' : 'bottom: 0'}}; {
  
  {tabBar.borderStyle? (tabBar.position=='top'? 'border-bottom: solid 1px '+tabBar.borderStyle + ';' : 'border-top: solid 1px '+tabBar.borderStyle + ';') : ''}}">    
  <block wx:for="{
  
  {tabBar.list}}" wx:key="pagePath">    
    <navigator url="{
  
  {item.pagePath}}" open-type="redirect" class="{
  
  {item.clas}}" style="{
  
  {item.active? 'color: '+(item.selectedColor? item.selectedColor : tabBar.selectedColor) : ''}}">    
      <image src="{
  
  {item.selectedIconPath}}" wx:if="{
  
  {item.active}}" class="img"></image>    
      <image src="{
  
  {item.iconPath}}" wx:if="{
  
  {!item.active}}" class="img"></image>  
      <text>{
  
  {item.text}}</text>    
    </navigator>    
    </block>  
    <view class="clear"></view>    
  </view>    
</template>   

在app.json中无需定义“tabBar”

评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值