很简单 TabBar是一个对象,然后项存在list中,list是和 对象,最少2个项 最多5个:

uniAPP  tabBar 设置_icouniAPP  tabBar 设置_数组_02

/*tabBar是一个对象*/
    "tabBar":{
        "color":"#ff55ff",  //tabBar 字体颜色
        "selectedColor":"#007AFF",  //tabBar 被选择选择颜色
        "borderStyle":"black",      //tabBar 上边框颜色
        "backgroundColor":"#ffffff",    //tabBar背景颜色
        /* 最少2个 最多5个 导航项*/
        "list":[
            {
                //注意pagePath 路劲要和上面的包路劲一样
                "pagePath":"pages/index/index",
                "text":"首页",
                "iconPath":"static/logo/home.png",
                "selectedIconPath":"static/logo/homeA.png"
            },
            {
                "pagePath":"pages/search/search",
                "text":"搜索",
                "iconPath":"static/logo/search.png",
                "selectedIconPath":"static/logo/searchA.png"
            },
            {
                "pagePath":"pages/me/me",
                "text":"我的",
                "iconPath":"static/logo/me.png",
                "selectedIconPath":"static/logo/meA.png"
            }
        ]
    }

View Code

放在pages.json中

 效果:uniAPP  tabBar 设置_h5_03

 

 

官方说:

如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定一级导航栏,以及 tab 切换时显示的对应页。

在 pages.json 中提供 tabBar 配置,不仅仅是为了方便快速开发导航,更重要的是在App和小程序端提升性能。在这两个平台,底层原生引擎在启动时无需等待js引擎初始化,即可直接读取 pages.json 中配置的 tabBar 信息,渲染原生tab。

Tips

  • 当设置 position 为 top 时,将不会显示 icon
  • tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。
  • tabbar 切换第一次加载时可能渲染不及时,可以在每个tabbar页面的onLoad生命周期里先弹出一个等待雪花(hello uni-app使用了此方式)
  • tabbar 的页面展现过一次后就保留在内存中,再次切换 tabbar 页面,只会触发每个页面的onShow,不会再触发onLoad。
  • 顶部的 tabbar 目前仅微信小程序上支持。需要用到顶部选项卡的话,建议不使用 tabbar 的顶部设置,而是自己做顶部选项卡,可参考 hello uni-app->模板->顶部选项卡。

 

属性说明:

属性

类型

必填

默认值

描述

平台差异说明

color

HexColor


 

tab 上的文字默认颜色

 

selectedColor

HexColor


 

tab 上的文字选中时的颜色

 

backgroundColor

HexColor


 

tab 的背景色

 

borderStyle

String


black

tabbar 上边框的颜色,可选值 black/white

App 2.3.4+ 支持其他颜色值、H5 3.0.0+

blurEffect

String


none

iOS 高斯模糊效果,可选值 dark/extralight/light/none(参考:​​使用说明​​)

App 2.4.0+ 支持、H5 3.0.0+(只有最新版浏览器才支持)

list

Array


 

tab 的列表,详见 list 属性说明,最少2个、最多5个 tab

 

position

String


bottom

可选值 bottom、top

top 值仅微信小程序支持

fontSize

String


10px

文字默认大小

App 2.3.4+、H5 3.0.0+

iconWidth

String


24px

图标默认宽度(高度等比例缩放)

App 2.3.4+、H5 3.0.0+

spacing

String


3px

图标和文字的间距

App 2.3.4+、H5 3.0.0+

height

String


50px

tabBar 默认高度

App 2.3.4+、H5 3.0.0+

midButton

Object


 

中间按钮 仅在 list 项为偶数时有效

App 2.3.4+、H5 3.0.0+

其中 list 接收一个数组,数组中的每个项都是一个对象,其属性值如下:

属性

类型

必填

说明

pagePath

String


页面路径,必须在 pages 中先定义

text

String


tab 上按钮文字,在 App 和 H5 平台为非必填。例如中间可放一个没有文字的+号图标

iconPath

String


图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 position 为 top 时,此参数无效,不支持网络图片,不支持字体图标

selectedIconPath

String


选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 position 为 top 时,此参数无效

midButton 属性说明

属性

类型

必填

默认值

描述

width

String


80px

中间按钮的宽度,tabBar 其它项为减去此宽度后平分,默认值为与其它项平分宽度

height

String


50px

中间按钮的高度,可以大于 tabBar 高度,达到中间凸起的效果

text

String


 

中间按钮的文字

iconPath

String


 

中间按钮的图片路径

iconWidth

String


24px

图片宽度(高度等比例缩放)

backgroundImage

String


 

中间按钮的背景图片路径

 

 

  • 中间带+号的tabbar模板例子,​​参考​​。可跨端,但+号不凸起。如需中间凸起,配置tabbar的midButton。


作者:​​咸瑜​​​