微信小程序底部自定义tabBar

   一、最简单底部导航栏
   在 app.json 内配置(限制:菜单栏最多5个,样式、图片不好个性化设置)

 "tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "/assets/tabBar/icon_component.png",
        "selectedIconPath": "/assets/tabBar/icon_component_HL.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/contact/index",
        "iconPath": "/assets/tabBar/icon_API.png",
        "selectedIconPath": "/assets/tabBar/icon_API_HL.png",
        "text": "联系客服"
      }
    ]
  }

二、自定义底部导航栏

1、在 app.json 内配置 (custom:最低适配版本2.5.0)

"tabBar": { // 虽然配置后并不生效,但是不能省
   "custom": true,    // 是否启用自定义底部导航栏
   "color": "#7A7E83",
   "selectedColor": "#3cc51f",
   "borderStyle": "black",
   "backgroundColor": "#ffffff",
   "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "/assets/tabBar/icon_component.png",
        "selectedIconPath": "/assets/tabBar/icon_component_HL.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/contact/index",
        "iconPath": "/assets/tabBar/icon_API.png",
        "selectedIconPath": "/assets/tabBar/icon_API_HL.png",
        "text": "联系客服"
      }
    ]
},

"usingComponents": {  // 在 app.json 内开启全局配置
   "v-tabBar": "custom-tab-bar/index"
}

2、自定义 tabBar 组件   (文件夹名必须为custom-tab-bar,必须和pages在同一级目录;文件名必须为 index 命名)

custom-tab-bar 代码请参考:微信小程序api-自定义tabBar

 备注: list中的pagePath一定要写绝对路径/pages开头

3、在 pages 的 xxx.js 新增 onShow 方法

onShow: function() {
  if(typeof this.getTabBar === 'function' && this.getTabBar()){
    this.getTabBar().setData({selected: 1});
  }
}

参考:微信小程序自定义tabbar

          uni-app适配自定义tabBar

说明: 微信小程序自带 tabBar 可以在 <web-view> 标签上显示; 自定义 tabBar 无法在<web-view> 标签上显示【如果将 <view>标签改成<cover-view>标签,则可以在<web-view> 标签上显示,但是tabBar会出现页面加载时无法固定显示在底部的问题】

        

          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值