uni-app学习笔记二十一--pages.json中tabBar设置底部菜单项和图标_uniapp page.json tabbar 图标只能放在static吗
如果应用是一个多 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->模板->顶部选项卡。
属性说明:
其中 list 接收一个数组,数组中的每个项都是一个对象,其属性值如下:
tarBar写于page.json中,与pages,globalStyle并列
示例代码:
\"tabBar\": {\"color\": \"#999\",\"selectedColor\": \"#2B9939\",\"borderStyle\": \"white\",\"list\": [{\"pagePath\" : \"pages/index/index\",\"text\": \"首页\",\"iconPath\": \"/static/images/tabBar/home.png\",\"selectedIconPath\": \"/static/images/tabBar/home-h.png\"},{\"pagePath\" : \"pages/classfy/classfy\",\"text\": \"分类\",\"iconPath\": \"/static/images/tabBar/classify.png\",\"selectedIconPath\": \"/static/images/tabBar/classify-h.png\"},{\"pagePath\" : \"pages/user/user\",\"text\": \"我的\",\"iconPath\": \"/static/images/tabBar/user.png\",\"selectedIconPath\": \"/static/images/tabBar/user-h.png\"}]}
效果: