微信小程序app.json 是一个对整个小程序的全局配置。这个文件描述了小程序的生命周期、页面路径、窗口表现、底部导航栏、网络超时时间等配置信息。下面是一个简单的 app.json 示例(微信小程序app.json):
json
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/about/about"
],
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "小程序示例",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light",
"enablePullDownRefresh": false
},
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "images/home.png",
"selectedIconPath": "images/home-selected.png"
},
{
"pagePath": "pages/logs/logs",
"text": "日志",
"iconPath": "images/logs.png",
"selectedIconPath": "images/logs-selected.png"
}
],
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"backgroundColor": "#ffffff",
"borderStyle": "black",
"position": "bottom"
},
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"debug": false,
"sitemapLocation": "sitemap.json"
}
以下是 app.json 中各个配置项的解释:
"pages":页面路径列表,第一个页面是小程序的首页(启动页)。
"window":用于设置小程序的窗口表现。
navigationBarBackgroundColor:导航栏背景颜色。
navigationBarTextStyle:导航栏标题颜色,仅支持 black/white。
navigationBarTitleText:导航栏标题文字内容。
backgroundColor:窗口的背景色。
backgroundTextStyle:下拉 loading 的样式,仅支持 dark/light。
enablePullDownRefresh:是否开启下拉刷新。
"tabBar":底部导航栏的配置。
"list":导航栏的按钮列表。
pagePath:页面路径,必须在 pages 中先定义。
text:按钮文字。
iconPath:按钮图标路径。
selectedIconPath:选中时的按钮图标路径。
其他配置还有 color、selectedColor、backgroundColor、borderStyle 和 position。
"networkTimeout":网络请求的超时时间。
"debug":是否开启 debug 模式,默认关闭。
"sitemapLocation":指明 sitemap.json 的位置;开发者工具在真机预览时,会读取这个配置文件,以决定哪些页面可以预览。
开发者可以根据实际需求,在 app.json 中添加或修改配置信息。需要注意的是,app.json 中的配置项必须严格遵循 JSON 格式,不能添加注释,否则会导致配置解析失败。