全局配置
通过
app.json文件来配置一些全局属性,如页面文件路径、窗口变现、网络超时等
1 | { |
pages
必填,接受字符串数组格式
用于指定小程序包含的页面,每个页面的格式为
路径 + 文件名;文件名不需要带后缀,框架会自动寻找路径下.json,.js,.wxml,.wxss四个文件进行整合数组的第一项为初始页,新增或减少页面都要修改该数组
1 | "pages": [ |
window
设置状态栏、导航、标题、窗口背景色
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| navigationBarBackgroundColor | HexColor | #000000 | 导航栏背景颜色 |
| navigationBarTextStyle | String | white | 导航栏标题颜色,仅支持 black/white |
| navigationBarTitleText | String | 导航栏标题文字内容 | |
| backgroundColor | HexColor | #ffffff | 窗口背景色 |
| backgroundTextStyle | String | dark | 下拉背景字体、loading 图的样式,仅支持 dark/light |
| enablePullDownRefresh | Boolean | false | 是否开启下拉刷新,详见页面相关事件处理函数 |
| onReachBottomDistance | Number | 50 | 页面上拉触底事件触发时距页面底部距离,单位为 px |
1 | window: { |

tabBar
如果小程序是一个多 tab 应用,可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面
position 为 top 时不会显示 icon
list 是一个数组,最少配置2个、最多5个 tab,tab 按数组的顺序排序
| 属性 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| color | HexColor | 是 | tab 上文字默认颜色 | |
| selectedColor | HexColor | 是 | tab 上文字选中时的颜色 | |
| backgroundColor | HexColor | 是 | tab 背景色 | |
| list | Array | 是 | tab 列表,详见 list 属性说明,最少2个、最多5个 | |
| borderStyle | String | 否 | black | tabbar上边框颜色, 仅支持 black/white |
| position | String | 否 | bottom | 可选值 bottom、top |
list 接受对象数组,对象属性值如下:
| 属性 | 类型 | 必填 | 说明 |
|---|---|---|---|
| pagePath | String | 是 | 页面路径,必须在 pages 中先定义 |
| text | String | 是 | tab 上按钮文字 |
| iconPath | String | 否 | 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片 |
| selectedIconPath | String | 否 | 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 |

networkTimeout
设置各种请求的超时时间,如上传下载、HTTP、Socket等
单位为毫秒
| 属性 | 类型 | 必填 | 说明 |
|---|---|---|---|
| request | Number | 否 | wx.request 的超时时间,默认为:60000 |
| connectSocket | Number | 否 | wx.connectSocket 的超时时间,默认为:60000 |
| uploadFile | Number | 否 | wx.uploadFile 的超时时间,默认为:60000 |
| downloadFile | Number | 否 | wx.downloadFile 的超时时间,默认为:60000 |
1 | networkTimeout: { |
debug
默认为
false, 在开发者工具中开启debug模式在控制台面板中以 info 的形式输出如
Page 注册、路由跳转、数据更新等调试信息
工具配置
通过
project.config.json文件来进行个性化配置,如设置界面颜色、编译条件等开发工具会在每个项目根目录中生成这样一个配置文件
| 字段名 | 类型 | 说明 |
|---|---|---|
| miniprogramRoot | Path String | 指定小程序源码的目录(需为相对路径) |
| qcloudRoot | Path String | 指定腾讯云项目的目录(需为相对路径) |
| setting | Object | 项目设置 |
setting 字段中可以设置如下属性:
| 字段名 | 类型 | 说明 |
|---|---|---|
| es6 | Boolean | 是否启用 es5 转 es6 |
| postcss | Boolean | 上传代码时样式是否自动补全 |
| minified | Boolean | 上传代码时是否自动压缩 |
| urlCheck | Boolean | 是否检查安全域名和 TLS 版本 |
| newFeature | Boolean | 是否支持新特性 |
1 | { |
页面配置
每一个小程序页面也可以单独使用
.json文件来对本页面的窗口表现进行配置页面的
.json只能设置window相关的配置项,会覆盖app.json的window中相同的配置项
disableScroll属性只对单独页面有效
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| navigationBarBackgroundColor | HexColor | #000000 | 导航栏背景颜色 |
| navigationBarTextStyle | String | white | 导航栏标题颜色,仅支持 black/white |
| navigationBarTitleText | String | 导航栏标题文字内容 | |
| backgroundColor | HexColor | #ffffff | 窗口背景色 |
| backgroundTextStyle | String | dark | 下拉背景字体、loading 图的样式,仅支持 dark/light |
| enablePullDownRefresh | Boolean | false | 是否开启下拉刷新,详见页面相关事件处理函数 |
| onReachBottomDistance | Number | 50 | 页面上拉触底事件触发时距页面底部距离,单位为 px |
| disableScroll | Boolean | false | 设置为 true 则页面整体不能上下滚动 |