今天打算开始实战一个微信小程序项目,一开始就踩坑了,正确设置了TabBar,但是TabBar就是不能显示出来,后面才找到原因,这里记录下:
app.json正确代码:
{ "pages":[ "pages/index/index", "pages/leader/leader", "pages/leader/stories/stories", "pages/leader/authors/authors", "pages/stack/stack", "pages/stack/booklist/booklist", "pages/stack/booklist/bookdetail/bookdetail", "pages/bookdesk/bookdesk", "pages/mine/mine", "pages/mine/news/news", "pages/logs/logs" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "网易蜗牛读书", "navigationBarTextStyle":"black" }, "tabBar":{ "color":"#999999", "selectedColor":"#444444", "backgroungColor":"#ffffff", "borderStyle":"#e0e0e0", "list": [ { "pagePath":"pages/leader/leader", "iconPath": "assets/icons/lingdu.png", "selectedIconPath": "assets/icons/lingdu_sel.png", "text":"领读" }, { "pagePath":"pages/stack/stack", "iconPath": "assets/icons/stack.png", "selectedIconPath": "assets/icons/stack_sel.png", "text":"分类" }, { "pagePath": "pages/bookdesk/bookdesk", "iconPath": "assets/icons/bookdesk.png", "selectedIconPath": "assets/icons/bookdesk_sel.png", "text":"书桌" }, { "pagePath":"pages/mine/mine", "iconPath": "assets/icons/mine.png", "selectedIconPath": "assets/icons/mine_sel.png", "text":"我的" } ] }}
这里注意显示解决有两种方式:
1.pages里的首个页面必须在list数组里有配置,所以在lists数组里加一个字典对象即可。
{ "pagePath":"pages/index/index", "iconPath": "assets/icons/index.png", "selectedIconPath": "assets/icons/index_sel.png", "text":"首页" }
但是我的TabBar又不想有这个item显示,这里看第二种解决办法。
2.pages数组的第一项必须是tabBar的list数组的一员:
这里有个疑惑:
百度了解决方法,显示将list数组加了index的模块item,后面不想要index模块在TabBar显示,然后又删除再运行,问题就解决了,也没有设置pages数组的第一项必须是tabBar的list数组的一员。
解决了就好,知道的大神可以留言告诉我哟!