WeChat Mini Program Development - Configuration
We use app.json
files to configure the WeChat applet globally, determine the path of the page file, window performance, set network timeout, set multiple tabs, etc. The simple understanding is the configuration file.
Configuration item table:
Attributes |
Types of |
Required |
describe |
pages |
Array |
Yes |
set page path |
window |
Object |
no |
Set the window behavior of the default page |
tabBar |
Object |
no |
Set the behavior of the bottom tab |
networkTimeout |
Object |
no |
Set network timeout |
debug |
Boolean |
no |
Set whether to enable debug mode |
pages
Accepts an array, each item is a string, representing the [path + file name] information of the corresponding page, the file name does not need to write a suffix, because the framework will automatically find the path of .json, .js, .wxml, .wxss Four files are integrated. The first value of the pages property is the system startup page. To add or delete pages in the applet, the pages array needs to be modified.
{ "pages":[ "pages/logs/logs", "pages/index/index" ] } |
window
The windows property is used to set the status bar, navigation bar, title, and window background color of the applet.
Attributes |
Types of |
Defaults |
describe |
navigationBarBackgroundColor |
HexColor |
#000000 |
Navigation bar background color, such as "#000000" |
navigationBarTextStyle |
String |
white |
Navigation bar title color, only supports black/white |
navigationBarTitleText |
String |
|
Navigation bar title text content |
backgroundColor |
HexColor | #ffffff |
the background color of the window |
backgroundTextStyle |
String |
dark |
Drop-down background font, loading image style, only supports dark/light |
enablePullDownRefresh |
Boolean |
false |
Whether to enable pull-down refresh, see page-related event handlers for details. |
tabBar
If our applet is a multi-tab application (there is a tab bar at the bottom of the client window to switch pages), then we can specify the performance of the tab bar and the corresponding page displayed when the tab is switched through the tabBar configuration item.
tabBar is an array, you can only configure a minimum of 2 and a maximum of 5 tabs , and the tabs are sorted in the order of the array.
Attributes |
Types of |
Required |
Defaults |
describe |
color |
HexColor |
Yes |
Default color of text on tabs |
|
selectedColor |
HexColor |
Yes |
The color of the text on the tab when it is selected |
|
backgroundColor |
HexColor |
Yes |
background color of the tab |
|
borderStyle |
String |
no |
black |
The color of the border on the tabbar, only black/white is supported |
list |
Array |
Yes |
The list of tabs, see the list attribute description for details, at least 2 and at most 5 tabs |
where list accepts an array, and each item in the array is an object with the following property values:
Attributes |
Types of |
Required |
illustrate |
pagePath |
String |
Yes |
The page path, which must be defined first in pages |
text |
String |
Yes |
button text on tab |
iconPath |
String |
Yes |
Image path, icon size is limited to 40kb |
selectedIconPath |
String |
Yes |
The image path when selected, the icon size is limited to 40kb |
networkTimeout
The timeout period for various network requests can be set.
Attributes |
Types of |
Required |
illustrate |
request |
Number |
no |
The timeout of wx.request, in milliseconds |
connectSocket |
Number |
no |
The timeout of wx.connectSocket, in milliseconds |
uploadFile |
Number |
no |
The timeout of wx.uploadFile, in milliseconds |
downloadFile |
Number |
no |
The timeout of wx.downloadFile, in milliseconds |
debug
可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息page的注册,页面路由,数据更新,事件触发。可以帮助开发者快速定位一些常见的问题。
参照豆瓣电影微信小程序的一个完整的app.json如下:
{ "pages": [ "pages/featured/featured", "pages/splash/splash", "pages/movie/movie", "pages/usbox/usbox", "pages/search/search", "pages/profile/profile" ], "window": { "navigationBarBackgroundColor": "#000000", "navigationBarTextStyle": "white", "navigationBarTitleText": "豆瓣电影", "backgroundColor": "#ffffff", "backgroundTextStyle": "dark", "enablePullDownRefresh": false }, "tabBar": { "color": "#ccc", "selectedColor": "#35495e", "borderStyle": "white", "backgroundColor": "#fafafa", "position": "bottom", "list": [ { "text": "推荐电影", "pagePath": "pages/featured/featured", "iconPath": "images/featured.png", "selectedIconPath": "images/featured-actived.png" }, { "text": "正在上映", "pagePath": "pages/usbox/usbox", "iconPath": "images/usbox.png", "selectedIconPath": "images/usbox-actived.png" }, { "text": "搜索", "pagePath": "pages/search/search", "iconPath": "images/search.png", "selectedIconPath": "images/search-actived.png" }, { "text": "资讯", "pagePath": "pages/splash/splash", "iconPath": "images/news.png", "selectedIconPath": "images/news-actived.png" }, { "text": "我的", "pagePath": "pages/profile/profile", "iconPath": "images/profile.png", "selectedIconPath": "images/profile-actived.png" } ] }, "networkTimeout": { "request": 10000, "connectSocket": 10000, "uploadFile": 10000, "downloadFile": 10000 }, "debug": true } |
另外,每一个小程序页面也可以使用page.json文件对本页面的窗口表现进行配置。 页面中配置项会覆盖 app.json的 window 中相同的配置项。因为只能设置 window 相关的配置项,所以无需写 window 这个键,如:
{ "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black", "navigationBarTitleText": "微信接口功能演示", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light" } |