app.json剖析
1.pages存放页面路径,类型为Array是唯一一个在app.json必须存在的配置项
小程序中新增/减少页面,都需要对pages数组进行修改。文件名不需要写文件后缀,因为框架会自动去寻找路径.json.js.wxml.wxss的四个文件进行整合。示例如下:
"pages": [
"pages/index/index",
"pages/more/more",
"pages/discover/discover"
],
2.window类型为Object可选择不设置,作用设置默认页面的窗口表现
具体设置小程序的状态栏、导航栏、标题、窗口背景色,官方属性图:
具体示例如下:
"window": {
"backgroundTextStyle":
"light",
"navigationBarBackgroundColor":
"#FFFFFF",
"navigationBarTitleText":
"母婴大卖场",
"navigationBarTextStyle":
"black",
"backgroundColor":
"#eeeeee",
"onReachBottomDistance":
"50"
},
3.tabBar类型为Object,可以不设置
具体示例如下:
"tabBar": {
"list": [//tab的列表
{
"pagePath":
"pages/index/index",//页面路径,必须在pages中先定义 必须设置
"text":
"首页", //tab上按钮文字 必须设置
"iconPath":
"images/ic_main_dark@3x.png",// 图片路径icon
当postion为top时此参数无效
"selectedIconPath":
"images/ic_main_light@3x.png"//选中时的图片路径 当postion为top时此参数无效
},
{
"pagePath":
"pages/discover/discover",
"text":
"发现",
"iconPath":
"images/ic_finder_dark@3x.png",
"selectedIconPath":
"images/ic_finder_light@3x.png"
},
{
"pagePath":
"pages/more/more",
"text":
"我的",
"iconPath":
"images/ic_more_dark@3x.png",
"selectedIconPath":
"images/ic_more_light@3x.png"
}
],
"color":
"#666", //tab上的文字默认颜色
"selectedColor":
"#333", //tab上的文字选中时的颜色
"borderStyle":
"black", //tab上边框的颜色,仅支持black/white
"backgroundColor":
"#333",//tab的背景色
"position":
"botton"
// 默认bottom 可选值 bottom、top, 当设置 position 为 top 时,将不会显示 icon
},
4.networkTimeout可以设置各种网络请求的超时时间。
官方文档:
具体示例:
"networkTimeout": {
"request":
5000,
"connectSocket":
5000,
"uploadFile":
5000,
"downloadFile":
5000
},
5.debug
可以在开发者工具中开启debug模式,在开发者工具的控制台面板,调试信息以info的形式给出,其信息有Pages的注册,页面路由,数据更新,事件触发。可以帮助开发者快速定位一些常见的问题。具体用法:
"debug":
true
app.json整体代码具体示例如下:
{
"pages": [
"pages/index/index",
"pages/more/more",
"pages/discover/discover"
],
"window": {
"backgroundTextStyle":
"light",
"navigationBarBackgroundColor":
"#FFFFFF",
"navigationBarTitleText":
"母婴大卖场",
"navigationBarTextStyle":
"black",
"backgroundColor":
"#eeeeee",
"onReachBottomDistance":
"50"
},
"tabBar": {
"list": [
{
"pagePath":
"pages/index/index",
"text":
"首页",
"iconPath":
"images/ic_main_dark@3x.png",
"selectedIconPath":
"images/ic_main_light@3x.png"
},
{
"pagePath":
"pages/discover/discover",
"text":
"发现",
"iconPath":
"images/ic_finder_dark@3x.png",
"selectedIconPath":
"images/ic_finder_light@3x.png"
},
{
"pagePath":
"pages/more/more",
"text":
"我的",
"iconPath":
"images/ic_more_dark@3x.png",
"selectedIconPath":
"images/ic_more_light@3x.png"
}
],
"color":
"#666",
"selectedColor":
"#333",
"borderStyle":
"black",
},
"networkTimeout": {
"request":
5000,
"connectSocket":
5000,
"uploadFile":
5000,
"downloadFile":
5000
},
"debug":
true
}