小程序配置
全局配置
app.json 文件用来对小程序进行全局配置,页面路径、窗口表现、设置网络超时时间、设置 tabBar 等。
如果页面内存在的 json 文件,配置同样的选项,则会覆盖全局的配置(页面内的 json 文件只能配置部分选项,具体可参看页面内的配置)。
以下是示例配置文件 app.json:
{
"entryPagePath": "pages/index/index",
"pages": [
"pages/welcome/welcome",
"pages/tab1/tab1",
"pages/tab2/tab2"
],
"window": {
"navigationBarTitleText": "芒果小程序 Demo"
},
"tabBar": {
"list": [
{
"pagePath": "pages/tab1/tab1",
"text": "tab1"
},
{
"pagePath": "page/tab2/tab2",
"text": "tab2"
}
]
}
}
}
entryPagePath
指定小程序的默认启动路径(首页)。如果不填,将默认为 pages 列表的第一项。不支持带页面路径参数。
pages
用于指定小程序由哪些页面组成,每一项都对应一个页面的 路径+文件名 信息,文件名不需要写文件后缀,增加或减少页面,都需要对 pages 数组进行手动增加或减少,pages 数组中的元素不能重复。
window
用于设置小程序全局的状态栏、标题、窗口表现等。
属性 | 类型 | 默认值 | 描述 |
---|---|---|---|
navigationBarBackgroundColor | HexColor(十六进制颜色值) | #000000 | 导航栏背景颜色,如 #000000 |
navigationBarTextStyle | String | white | 导航栏标题颜色,目前仅支持 black / white |
navigationBarTitleText | String | - | 导航栏标题文字内容,字数不宜过多 |
navigationStyle | String | default | 导航栏样式,仅支持以下值:1. default(默认样式), 2. 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 | auto / portrait / landscape | portrait | 屏幕旋转设置 |
enableHalfPageVideoUpdateEvent | Boolean | false | 是否接收半屏小程序视频每秒的心跳,用于根据当前视频进度跳转小程序页面显示。 |
示例代码:
{
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "MGTV Mini Demo",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
}
tabBar
tabBar 用来配置小程序底部或者顶部的 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 |
其中 list 是数组类型,只能配置最少 2 个、最多 5 个 tab。tab 按数组的顺序排序,每个项都是一个独立的对象,其可配置值如下:
属性 | 类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
pagePath | String | 是 | - | 页面路径,必须在 pages 中先定义 |
text | String | 是 | - | tab 上按钮文字 |
iconPath | String | 否 | - | 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。当 position 为 top 时,不显示 icon。 |
selectedIconPath | String | 否 | black | 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。当 position 为 top 时,不显示 icon。 |