全局配置
小程序根目录下的 app.json 文件用来对微信小程序进行全局配置。文件内容为一个 JSON 对象。
配置项
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
| entryPagePath | string | 否 | 小程序默认启动首页 |
| pages | string[] | 是 | 页面路径列表 |
| window | Object | 否 | 全局的默认窗口表现 |
| tabBar | Object | 否 | 底部 tab 栏的表现 |
| networkTimeout | Object | 否 | 网络超时时间 |
| debug | boolean | 否 | 是否开启 debug 模式,默认关闭 |
| subpackages | Object[] | 否 | 分包结构配置 |
| preloadRule | Object | 否 | 分包预下载规则 |
| workers | string | 否 | Worker 代码放置的目录 |
| requiredBackgroundModes | string[] | 否 | 需要在后台使用的能力,如「音乐播放」 |
| plugins | Object | 否 | 使用到的插件 |
| resizable | boolean | 否 | PC 小程序是否支持用户任意改变窗口大小 |
| usingComponents | Object | 否 | 全局自定义组件配置 |
| permission | Object | 否 | 小程序接口权限相关设置 |
| sitemapLocation | string | 是 | 指明 sitemap.json 的位置 |
| style | string | 否 | 指定使用升级后的 weui 样式 |
| useExtendedLib | Object | 否 | 指定需要引用的扩展库 |
| entranceDeclare | Object | 否 | 微信消息用小程序打开 |
| darkmode | boolean | 否 | 小程序支持 DarkMode |
| themeLocation | string | 否 | 指明 theme.json 的位置 |
| lazyCodeLoading | string | 否 | 配置自定义组件代码按需注入 |
| singlePage | Object | 否 | 单页模式相关配置 |
entryPagePath
指定小程序的默认启动路径(首页),常见情景是从微信聊天列表页下拉启动、小程序列表启动等。如果不填,将默认为 pages 列表的第一项。不支持带页面路径参数。
pages
用于指定小程序由哪些页面组成,每一项都对应一个页面的 路径(含文件名) 信息。文件名不需要写文件后缀,框架会自动去寻找对应位置的 .json, .js, .wxml, .wxss 四个文件进行处理。
未指定 entryPagePath 时,数组的第一项代表小程序的初始页面(首页)。
示例:
json
{
"pages": [
"pages/index/index",
"pages/logs/logs"
]
}window
用于设置小程序的状态栏、导航条、标题、窗口背景色。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| navigationBarBackgroundColor | HexColor | #000000 | 导航栏背景颜色 |
| navigationBarTextStyle | string | white | 导航栏标题、状态栏颜色,仅支持 black / white |
| navigationBarTitleText | string | 导航栏标题文字内容 | |
| navigationStyle | string | default | 导航栏样式,仅支持 default / custom |
| backgroundColor | HexColor | #ffffff | 窗口的背景色 |
| backgroundTextStyle | string | dark | 下拉 loading 的样式,仅支持 dark / light |
| backgroundColorTop | string | #ffffff | 顶部窗口的背景色,仅 iOS 支持 |
| backgroundColorBottom | string | #ffffff | 底部窗口的背景色,仅 iOS 支持 |
| enablePullDownRefresh | boolean | false | 是否开启全局的下拉刷新 |
| onReachBottomDistance | number | 50 | 页面上拉触底事件触发时距页面底部距离,单位为 px |
| pageOrientation | string | portrait | 屏幕旋转设置,支持 auto / portrait / landscape |
tabBar
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 对应的页面的路径。
| 属性 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| color | HexColor | 是 | tab 上的文字默认颜色 | |
| selectedColor | HexColor | 是 | tab 上的文字选中时的颜色 | |
| backgroundColor | HexColor | 是 | tab 的背景色 | |
| borderStyle | string | 否 | black | tabbar 上边框的颜色, 仅支持 black / white |
| list | Array | 是 | tab 的列表,详见 list 属性说明,最少 2 个、最多 5 个 tab | |
| position | string | 否 | bottom | tabBar 的位置,仅支持 bottom / top |
| custom | boolean | 否 | false | 自定义 tabBar |
list
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
| pagePath | string | 是 | 页面路径,必须在 pages 中先定义 |
| text | string | 是 | tab 上按钮文字 |
| iconPath | string | 否 | 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px |
| selectedIconPath | string | 否 | 选中时的图片路径 |
networkTimeout
各类网络请求的超时时间,单位均为毫秒。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| request | number | 60000 | wx.request 的超时时间 |
| connectSocket | number | 60000 | wx.connectSocket 的超时时间 |
| uploadFile | number | 60000 | wx.uploadFile 的超时时间 |
| downloadFile | number | 60000 | wx.downloadFile 的超时时间 |
debug
可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息有 Page 的注册,页面路由,数据更新,事件触发等。可以帮助开发者快速定位一些常见的问题。
usingComponents
在此处声明的自定义组件视为全局自定义组件,在小程序内的页面或自定义组件中可以直接使用而无需再声明。
json
{
"usingComponents": {
"my-component": "/components/my-component/my-component"
}
}