微信小程序开发 专题
专题目录
您的位置:微信小程序开发 > 微信小程序开发专题 > 小程序配置
小程序配置
作者:--    发布时间:2019-11-20

配置


我们使用app.json文件来对微信小程序进行全局配置,决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。

以下是一个包含了所有配置选项的简单配置app.json

{
"pages": [
"pages/index/index",
"pages/logs/index"
],
"window": {
"navigationbartitletext": "demo"
},
"tabbar": {
"list": [{
"pagepath": "pages/index/index",
"text": "首页"
}, {
"pagepath": "pages/logs/logs",
"text": "日志"
}]
},
"networktimeout": {
"request": 10000,
"downloadfile": 10000
},
"debug": true
}
app.json 配置项列表
属性 类型 必填 描述
pages string array 设置页面路径
window object 设置默认页面的窗口表现
tabbar object 设置底部 tab 的表现
networktimeout object 设置网络超时时间
debug boolean 设置是否开启 debug 模式

pages

接受一个数组,每一项都是字符串,来指定小程序由哪些页面组成。每一项代表对应页面的【路径+文件名】信息,数组的第一项代表小程序的初始页面。小程序中新增/减少页面,都需要对 pages 数组进行修改。

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

如开发目录为:

pages/

pages/index/index.wxml

pages/index/index.js

pages/index/index.wxss

pages/logs/logs.wxml

pages/logs/logs.js

app.js

app.json

app.wxss

则,我们需要在 app.json 中写

{
"pages":[
"pages/index/index"
"pages/logs/logs"
]
}

window

用于设置小程序的状态栏、导航条、标题、窗口背景色。

属性 类型 默认值 描述
navigationbarbackgroundcolor hexcolor #000000 导航栏背景颜色,如"#000000"
navigationbartextstyle string white 导航栏标题颜色,仅支持 black/white
navigationbartitletext string   导航栏标题文字内容
backgroundcolor hexcolor #ffffff 窗口的背景色
backgroundtextstyle string dark 下拉背景字体、loading 图的样式,仅支持 dark/light
enablepulldownrefresh boolean false 是否开启下拉刷新,详见页面相关事件处理函数
onreachbottomdistance number 50 页面上拉触底事件触发时距页面底部距离,单位为px

注:hexcolor(十六进制颜色值),如"#ff00ff"

如 app.json :

{
"window":{
"navigationbarbackgroundcolor": "#ffffff",
"navigationbartextstyle": "black",
"navigationbartitletext": "微信接口功能演示",
"backgroundcolor": "#eeeeee",
"backgroundtextstyle": "light"
}
}

微信接口功能演示


tabbar

如果我们的小程序是一个多 tab 应用(客户端窗口的底部有tab栏可以切换页面),那么我们可以通过 tabbar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。

tip:

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

2. tabbar 是一个数组,只能配置最少2个、最多5个 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 可选值 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 时,此参数无效

networking 网络

networktimeout

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

属性说明:

属性 类型 必填 说明
request number wx.request的超时时间,单位毫秒
connectsocket number wx.connectsocket的超时时间,单位毫秒
uploadfile number wx.uploadfile的超时时间,单位毫秒
downloadfile number wx.downloadfile的超时时间,单位毫秒

debug

可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息有page的注册页面路由数据更新事件触发 。可以帮助开发者快速定位一些常见的问题。

page.json

每一个小程序页面也可以使用.json文件来对本页面的窗口表现进行配置。页面的配置比app.json全局配置简单得多,只是设置 app.json 中的 window 配置项的内容,页面中配置项会覆盖 app.json 的 window 中相同的配置项。

页面的.json只能设置window相关的配置项,以决定本页面的窗口表现,所以无需写window这个键,如:

属性 类型 默认值 描述
navigationbarbackgroundcolor hexcolor #000000 导航栏背景颜色,如"#000000"
navigationbartextstyle string white 导航栏标题颜色,仅支持 black/white
navigationbartitletext string   导航栏标题文字内容
backgroundcolor hexcolor #ffffff 窗口的背景色
backgroundtextstyle string dark 下拉背景字体、loading 图的样式,仅支持 dark/light
enablepulldownrefresh boolean false 是否开启下拉刷新,详见页面相关事件处理函数
disablescroll boolean false 设置为 true 则页面整体不能上下滚动;只在 page.json 中有效,无法在 app.json 中设置该项


{
"navigationbarbackgroundcolor": "#ffffff",
"navigationbartextstyle": "black",
"navigationbartitletext": "微信接口功能演示",
"backgroundcolor": "#eeeeee",
"backgroundtextstyle": "light"
}


网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册