app.json 是当前小程序的全局配置文件,包括了小程序的所有页面路径、界面表现、网络超时时间、底部 tab 等。
当小程序启动时,会自动读取 app.json 文件中的配置,根据配置生成对应的页面和组件、界面表现、网络超时时间、底部 tab等,app.json 在小程序运行过程中起着关键的作用。
pages用于指定小程序由哪些页面组成,每一项都对应一个页面的 路径(含文件名) 信息。
注意事项:
.json, .js,.wxml,.wxss 四个文件进行处理。entryPagePath 时,数组的第一项代表小程序的初始页面(首页)。window字段: 用于设置小程序的状态栏、导航条、标题、窗口背景色。
| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| navigationBarBackgroundColor | 导航栏背景颜色 | HexColor | #000000 |
| navigationBarTextStyle | 导航栏标题颜色,仅支持 black / white |
string | white |
| navigationBarTitleText | 导航栏标题文字内容 | string | |
| backgroundColor | 下拉 loading 的样式,仅支持 dark / light |
string | dark |
| enablePullDownRefresh | 是否开启全局的下拉刷新 | boolean | false |
| onReachBottomDistance | 页面上拉触底事件触发时距页面底部距离单位为 px | number | 50 |
tabbar定义小程序顶部、底部tab栏,用以实现页面之间的快速切换。
tabBar 配置项
| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| color | tab 上的文字默认颜色,仅支持十六进制颜色 | HexColor | |
| selectedColor | tab 上的文字选中时的颜色,仅支持十六进制颜色 | HexColor | |
| backgroundColor | tab 的背景色,仅支持十六进制颜色 | HexColor | |
| borderStyle | tabbar 上边框的颜色, 仅支持 black / white |
string | black |
| list | tab 的列表,详见 list 属性说明,最少 2 个、最多 5 个 tab |
||
| position | tabBar 的位置,仅支持 bottom / top |
string | bottom |
List 配置项:list 是一个数组,只能配置最少 2 个、最多 5 个 tab,tab 按数组的顺序排序,每个项都是一个对象。
| 属性 | 描述 | 类型 | 是否必填 |
|---|---|---|---|
| pagePath | 页面路径,必须在 pages 中先定义 | string | 是 |
| text | tab 上按钮文字 | string | 是 |
| iconPath | 图片路径,icon 大小限制为 40kb, 建议尺寸为 81px * 81px, |
string | 是 |
| selectedIconPath | 选中时的图片路径,icon 大小限制为 40kb, 建议尺寸为 81px * 81px,不支持网络图片。 |
string | 是 |