根据官方文档写的tabBar
-
先创建文件夹
- 图标:
images文件夹下的icon - 先删除原来
pages文件夹下的页面 - 在重新在
pages文件夹下新建四个页面,分别是:chat:消息doc:文档home:首页profile:我的
- 图标:
-
目录结构:

-
在每个页面文件夹下的
index.json中,写入:"navigationBarTitleText": "",这样便于辨认tabBar之间的切换。-
在
home页面中的index.json中{ "usingComponents": {}, "navigationBarTitleText": "首页" } -
在
chat页面中的index.json中{ "usingComponents": {}, "navigationBarTitleText": "消息" } -
在
doc页面中的index.json中{ "usingComponents": {}, "navigationBarTitleText": "文档" } -
在
profile页面中的index.json中{ "usingComponents": {}, "navigationBarTitleText": "我的" }
-
-
最后在
app.json中配置tabBar{ "pages":[ "pages/home/index", "pages/doc/index", "pages/chat/index", "pages/profile/index" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", "navigationBarTextStyle":"black" }, "tabBar": { "color": "#30c6c7", "selectedColor": "#fa8c57", "backgroundColor": "#f9f9f9", "borderStyle":"black", "position": "bottom", "list": [ { "pagePath": "pages/home/index", "text": "首页", "iconPath": "./images/icon/home.png", "selectedIconPath": "./images/icon/home_selected.png" }, { "pagePath": "pages/doc/index", "text": "文档", "iconPath": "./images/icon/document.png", "selectedIconPath": "./images/icon/document_selected.png" },{ "pagePath": "pages/chat/index", "text": "消息", "iconPath": "./images/icon/chat.png", "selectedIconPath": "./images/icon/chat_selected.png" },{ "pagePath": "pages/profile/index", "text": "我的", "iconPath": "./images/icon/user.png", "selectedIconPath": "./images/icon/user_selected.png" } ] }, "style": "v2", "sitemapLocation": "sitemap.json" } -
页面展示效果

本文档详细介绍了如何在小程序中创建并配置TabBar,包括删除原有页面、新建四个核心页面(首页、消息、文档、我的)、设置各页面的navigationBarTitleText以及在app.json中配置TabBar的样式和各个页面的路径、图标等信息,最终实现底部导航栏的切换效果。
5010

被折叠的 条评论
为什么被折叠?



