小程序开发------.json文件
.json
根据.json作用范围,可以将一个项目里面的.json文件分为两类:第一类:app.json;第二类:xxx.json;
app.json
app.json文件用来对微信小程序进行全局配置,决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。
app.json 配置项列表
属性 | 类型 | 必填 | 描述 |
---|---|---|---|
pages | String array | 必填 | 配置页面路径 |
widonw | object | 非必填 | 全局配置窗口样式 |
tabBar | object | 非必填 | 配置tabBar |
networkTimeOut | object | 非必填 | 配置网络请求的超时时间 |
debug | Boolean | 非必填 | 是否打开debug模式,默认为关闭 |
pages
用于指定小程序由哪些页面组成,每一项都对应一个页面的 路径+文件名 信息。文件名不需要写文件后缀,框架会自动去寻找对于位置的 .json, .js, .wxml, .wxss 四个文件进行处理。
快速创建小技巧:在pages里面配置页面路径的时候,如果该路径下没有文件,则系统会在该路径下面创建所有的.json、.js、.wxml、.wxss四个文件。
window
用于设置小程序的状态栏、导航条、标题、窗口背景色。
window-navigation
navigationBarStyle为custom:没有文字,只有右上角的操作按钮
属性 | 类型 | 默认值 | 描述 |
---|---|---|---|
navigationBarBackgroundColor | HexColor | #000000 | 导航栏背景颜色 |
navigationBarTextStyle | string | white | 导航栏文字颜色,目前只支持black和white |
navigationBarTitleText | string | 导航栏文字 | |
navigationStyle | String | default | 导航栏样式,仅支持default和custom(只保留右上角的功能,没有导航栏文字) |
window-background
属性 | 类型 | 默认值 | 描述 |
---|---|---|---|
backgroundColor | HexColor | #ffffff | 窗口的背景色 |
backgroundTextStyle | string | dark | 下拉 loading 的样式,仅支持 dark / light |
下拉刷新和上拉加载更多
属性 | 类型 | 默认值 | 描述 |
---|---|---|---|
enablePullDownRefresh | boolean | false | 是否全局开启下拉刷新。 |
onReachBottomDistance | number | 50 | 页面上拉触底事件触发时距页面底部距离,单位为px。 |
tabBar
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。
其中 list 接受一个数组,只能配置最少2个、最多5个 tab。tab 按数组的顺序排序,每个项都是一个对象,其属性值如下:
属性 | 类型 | 说明 |
---|---|---|
pagePath | string | 页面路径,必须在 pages 中先定义 |
text | string | tab按钮文字 |
iconPath | string | 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,不支持网络图片。 |
selectedIconPath | string | 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,不支持网络图片。 |
networkTimeout
网络请求的超时时间,单位为毫秒。支持的属性如下表:
属性 | 类型 | 默认 | 必填 | 描述 |
---|---|---|---|---|
request | number | 60000 | 非 | wx.request 的超时时间,单位毫秒。 |
connectSocket | number | 60000 | 非 | wx.connectSocket 的超时时间,单位毫秒。 |
uploadFile | number | 6000 | 非 | wx.uploadFile 的超时时间,单位毫秒。 |
downloadFile | number | 60000 | 非 | wx.downloadFile 的超时时间,单位毫秒。 |
子页面.json
每一个小程序页面也可以使用.json文件来对本页面的窗口表现进行配置。
页面的配置只能设置 app.json 中部分 window 配置项的内容,页面中配置项会覆盖 app.json 的 window 中相同的配置项。
页面的.json只能设置 window 相关的配置项,以决定本页面的窗口表现,所以无需写 window 这个键。