您的位置:首页 > 移动开发 > 微信开发

小程序框架学习2——(app.json)

2018-02-01 22:57 120 查看
2、app.json

(1)作用

app.json文件用来对微信小程序进行全局配置

有以下五种配置(决定页面文件的路径pages、窗口表现window、设置网络超时时间networkTimeout、设置tab按钮tabBar、设置调试debug )

属性类型必填描述
pagesString Array设置页面路径
windowObject设置默认页面的窗口表现
tabBarObject设置底部 tab 的表现
networkTimeoutObject设置网络超时时间
debugBoolean设置是否开启 debug 模式
例子

{
"pages":[

"pages/index/index",

"pages/logs/logs",

"pages/me/me"
],
"window":{

"navigationBarBackgroundColor": "#000000",

"navigationBarTextStyle": "white",

"navigationBarTitleText": "师赴",

"backgroundColor": "#000",

"backgroundTextStyle": "light",

"enablePullDownRefresh": true,

"onReachBottomDistance":50
},
"tabBar[/b]":
{

"list": [{

"pagePath": "pages/index/index",

"text": "首页",

"iconPath": "/img/index_normal.png",

"selectedIconPath": "/img/index_select.png"

},{

"pagePath":"pages/logs/logs",

"text": "日志",

"iconPath": "/img/index_normal.png",

"selectedIconPath": "/img/index_select.png"

},

{

"pagePath": "pages/me/me",

"text": "日志",

"iconPath": "/img/index_normal.png",

"selectedIconPath": "/img/index_select.png"

}],

"color": "#000000",

"selectedColor": "#ff0000",

"backgroundColor": "#9900ff00",

"borderStyle": "black",

"position":"top"
},
"networkTimeout":
{

"request": 60000,

"connectSocket": 60000,

"uploadFile": 60000,

"downloadFile": 60000
},
"debug":true
}

(2)pages

接受一个数组,每一项都是字符串,来指定小程序由哪些页面组成

数组的第一项代表小程序的初始页面

小程序中新增/减少页面,都需要对 pages 数组进行修改

文件名不需要写文件后缀,因为框架会自动去寻找路径下 .json, .js, .wxml, .wxss 四个文件进行整合

(3)window

属性

属性类型默认值描述
navigationBarBackgroundColorHexColor#000000导航栏背景颜色,如"#000000"
navigationBarTextStyleStringwhite导航栏标题颜色,仅支持 black/white
navigationBarTitleTextString导航栏标题文字内容
backgroundColorHexColor#ffffff窗口的背景色 下拉刷新窗口的背景色
backgroundTextStyleStringdark下拉背景字体、loading 图的样式,仅支持 dark/light
enablePullDownRefreshBooleanfalse是否开启下拉刷新,详见页面相关事件处理函数
onReachBottomDistanceNumber50页面上拉触底事件触发时距页面底部距离,单位为px
(4)tabBar

当设置 position 为 top 时,将不会显示 icon

tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序

tabBar属性
属性类型必填默认值描述
colorHexColortab 上的文字默认颜色
selectedColorHexColortab 上的文字选中时的颜色
backgroundColorHexColortab 的背景色
borderStyleStringblacktabbar上边框的颜色, 仅支持 black/white
listArraytab 的列表,详见 list 属性说明,最少2个、最多5个 tab
positionStringbottom可选值 bottom、top
list属性

属性类型必填说明
pagePathString页面路径,必须在 pages 中先定义
textStringtab 上按钮文字
iconPathString图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPathString选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效
(5)networkTimeout

可以设置各种网络请求的超时时间

属性类型必填说明
requestNumberwx.request的超时时间,单位毫秒,默认为:60000
connectSocketNumberwx.connectSocket的超时时间,单位毫秒,默认为:60000
uploadFileNumberwx.uploadFile的超时时间,单位毫秒,默认为:60000
downloadFileNumberwx.downloadFile的超时时间,单位毫秒,默认为:60000
(6)debug

可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息有Page的注册,页面路由,数据更新,事件触发 。 可以帮助开发者快速定位一些常见的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息