常用全局配置
小程序在根目录下的app.json文件中进行全局的配置
下面介绍部分常用的全局配置
官网配置参考文档:全局配置的属性
pages中是小程序的组成页面,每一项对应一个页面的路径(含文件名)信息。文件名不需要写后缀,框架会自动去寻找对于位置的 .json, .js, .wxml, .wxss 四个文件进行处理。有多少个页面此处就有多少项
数组的第一项代表小程序的初始页面(首页)。小程序中新增/减少页面,都需要对 pages 数组进行修改。
直接在pages选项中写页面路径,即可创建相应的页面
//app.json文件中
{
"pages": [//创建的页面
"pages/home/home",
"pages/index/index",
"pages/detail/detail",
"pages/logs/logs",
"pages/kind/kind",
"pages/user/user",
"pages/test/test",
"pages/cart/cart",
"pages/map/map"
],
"window": {
"navigationStyle": "default",//导航栏样式
"navigationBarBackgroundColor": "#f66",//导航栏背景颜色
"navigationBarTitleText": "小程序",//导航栏标题
"navigationBarTextStyle": "white",//导航栏标题颜色
"enablePullDownRefresh": true,// 会都开启全局的下拉刷新,如果有局部不需要的可以在局部配置中进行关闭
"backgroundTextStyle": "dark",//下拉loading样式 支持dark和light
"backgroundColor": "#efefef",//窗口的背景色
"onReachBottomDistance": 50 //页面上拉触底事件触发时距页面底部距离
},
"tabBar": {//底部导航栏的配置
"color": "#333",
"selectedColor": "#f66",
"backgroundColor": "#efefef",
"borderStyle": "white",
"list": [
{
"pagePath": "pages/home/home",
"text": "首页",
"iconPath": "resources/home.png",
"selectedIconPath": "resources/home_active.png"
},
{
"pagePath": "pages/kind/kind",
"text": "分类",
"iconPath": "resources/kind.png",
"selectedIconPath": "resources/kind_active.png"
},
{
"pagePath": "pages/cart/cart",
"text": "购物车",
"iconPath": "resources/cart.png",
"selectedIconPath": "resources/cart_active.png"
},
{
"pagePath": "pages/user/user",
"text": "我的",
"iconPath": "resources/user.png",
"selectedIconPath": "resources/user_active.png"
}
]
},
"networkTimeout": {//网络请求超时的配置
"request": 6000,
"connectSocket": 5000,
"uploadFile": 4000,
"downloadFile": 5000
},
"permission": {
"scope.userLocation": {
"desc": "小程序位置信息展示"
}
},
//当小程序需要使用 wx.navigateToMiniProgram 接口跳转到其他小程序时,需要先在配置文件中声明需要跳转的小程序 appId 列表,最多允许填写 10 个。
"navigateToMiniProgramAppIdList": [
],
"style": "v2",
"sitemapLocation": "sitemap.json",
"debug": false
}
常用页面配置
在页面的.json文件中进行局部的页面配置
页面中配置项在当前页面会覆盖 app.json 的 window 中相同的配置项
{
"navigationBarBackgroundColor": "#ff4001",
"navigationBarTitleText": "首页",
"backgroundColorTop": "#efefef",
"backgroundTextStyle": "light",
"enablePullDownRefresh": true,
"onReachBottomDistance": 50,
"usingComponents": {//页面自定义组件的配置
"prolist": "/components/prolist/prolist"
}
}
常用sitemap配置
小程序根目录下的 sitemap.json 文件用于配置小程序及其页面是否允许被微信索引,文件内容为一个 JSON 对象,如果没有 sitemap.json ,则默认为所有页面都允许被索引
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}