当前位置:网站首页>微信小程序_5,全局配置
微信小程序_5,全局配置
2022-06-21 06:44:00 【icestone_kai】
小程序根目录下的app.json是小程序的全局配置文件,常用配置如下:
1.pages
- 记录当前小程序所有页面的存放路径
2.windows - 全局配置小程序窗口的外观
3.tabBar - 设置小程序底部的tabBar效果
4.style - 是否启用新版的组件样式
window:
小程序窗口的组成部分:
了解window节点常用的配置项:
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| navigationBarTitleText | String | 字符串 | 导航栏标题文字的内容 |
| navigationBarBackgroundColor | HexColor | #000000 | 导航栏背景颜色,如#000000 |
| navigationBarTextStyle | String | white | 导航栏标题颜色,仅支持black/white |
| backgroundColor | HexColor | #ffffff | 窗口的背景色 |
| backgroundTextStyle | String | dark | 下拉loading的样式,仅支持dark/light |
| enablePullDownRefresh | Boolean | false | 是否开启全局下拉刷新 |
| onReachBottomDistance | Number | 50 | 页面上拉触底事件触发时距页面底部距离,单位为px |
- 以
navigationBar开头的是控制标题栏的 - 以
background开头的就是控制背景色之类的 - 剩下两个就是控制页面事件的
设置标题栏的文字:
app.json->window->navigationBarTitleText
设置导航栏的背景色:
app.json->window->navigationBarBackgroundColor

修改导航栏文字颜色:
app.json->window->navigationBarTextStyle
注意这里的可选值只有black/white
开启全局下拉刷新:
概念:下拉刷新是移动端的专有名词,指的是通过手指在屏幕上的下拉滑动操作,从而重新加载页面数据的行为
app.json->window->enablePullDownRefresh的值设置为true
"enablePullDownRefresh": true

注意:在app.json中开启下拉刷新的功能,它会作用在每个小程序页面
注意:此时在模拟器上下拉刷新之后会自动合上,但是在真机上面并不会,所以在开发中不要过于相信模拟器的运行效果
设置下拉刷新的窗口背景色:
当全局开启下拉刷新功能之后,默认的窗口背景为白色,如果自定义下拉刷新窗口的背景色:
app.json->window->backgroundColor:
设置下拉刷新时loading的样式:
当全局开启下拉刷新功能之后,默认窗口的loading样式为白色,如果要更改loading样式的效果,设置步骤:
app.json->window->backgroundTextStyle
设置上拉触底的距离:
概念:上拉触底是移动端的专有名词,通过手指在屏幕上的下拉滑动操作,从而加载更多数据的行为
app.json->window->onReachBottomDistance
注意:默认距离为50px,如果没有特殊需求,建议使用默认值即可:

tabBar
什么是tabBar:
tabBar是移动端应用常见的页面效果,用于实现多页面的快速切换,小程序中通常将其分为:
- 底部tabBar
- 顶部tabBar
注意:
- tabBar中只能配置最少2个,最多5个tab标签
- 当渲染顶部tabBar时,不显示icon,只显示文本

tabBar的6个组成部分:

- backgroundColor:tabBar的背景色
- selectedIconPath:选中时的图片路径
- borderStyle:tabBar上边框的颜色
- iconPath:未选中时的图片路径
- selectedColor:tab上的文字选中时的颜色
- color:tab上文字的默认(未选中)颜色
tabBar节点的配置项:
| 属性 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| position | String | 否 | bottom | tabBar的位置,仅支持bottom/top |
| borderStyle | String | 否 | black | tabBar上边框的颜色,仅支持black/white |
| color | HexColor | 否 | tabBar上文字的默认(未选中)颜色 | |
| selectedColor | HexColor | 否 | tab上的文字选中时的颜色 | |
| backgroundColor | HexColor | 否 | tabBar的背景色 | |
| list | Array | 是 | tab页签的列表,最少2个,最多5个 |
每个tab项的配置选项:
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
| pagePath | String | 是 | 页面路径,页面必须在pages中预先配置 |
| text | String | 是 | tab上显示的文字 |
| iconPath | String | 否 | 未选中时的图标路径,当position为top时,不显示icon |
| selectedPath | String | 否 | 选中时的图标路径,当position为top时,不显示icon |
如(看tabBar的配置):
app.json:
{
"pages": [
"pages/person/person",
"pages/usekey/usekey",
"pages/for/for",
"pages/hidden/hidden",
"pages/block/block",
"pages/if/if",
"pages/fuzhi/fuzhi",
"pages/chuancan/chuancan",
"pages/bindtap/bindtap",
"pages/mustache/mustache",
"pages/img/img",
"pages/button/button",
"pages/text/text",
"pages/swiper/swiper",
"pages/list/list",
"pages/index/index",
"pages/logs/logs"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#b70509",
"navigationBarTitleText": "微信小程序开发",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": true,
"backgroundColor": "#8eed97",
"onReachBottomDistance": 200
},
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "index",
"iconPath": "/images/index.png",
"selectedIconPath": "/images/indexSelected.png"
},{
"pagePath": "pages/person/person",
"text": "person",
"iconPath": "/images/person.png",
"selectedIconPath": "/images/personSelected.png"
}]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
运行:
配置tabBar:
步骤一:拷贝图标资源
1.把资料目录中的images文件夹,拷贝到小程序项目跟目录中
2.将需要用到的小图标分为3组,每组两个,其中:
- 图片名称中包含-active的是选中之后的图标
- 名字中不包含-active的是默认图标

步骤二:新建三个对应的tab页面:
通过app.json文件的pages节点,快速新建3个对应的tab页面,示例代码如下:
"pages": [
"pages/person/person",
"pages/usekey/usekey",
"pages/for/for",
]
- 注意,tabBar中的页面必须放在app.json的page中的最前面,否则tab页签会无法正常显示,如:
app.json:
{
"pages": [
"pages/index/index",
"pages/person/person",
"pages/usekey/usekey",
"pages/for/for",
"pages/hidden/hidden"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#b70509",
"navigationBarTitleText": "微信小程序开发",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": true,
"backgroundColor": "#8eed97",
"onReachBottomDistance": 200
},
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "index",
"iconPath": "/images/index.png",
"selectedIconPath": "/images/indexSelected.png"
},{
"pagePath": "pages/person/person",
"text": "person",
"iconPath": "/images/person.png",
"selectedIconPath": "/images/personSelected.png"
}]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
tabBar中的index,person,在pages中也要放在前面
边栏推荐
- Google Earth Engine(GEE)——全球农田有机土壤碳和氮排放(1992-2018年度)数据集
- 天气预报小程序源码/天气类微信小程序源码
- 154-Solana分发token
- Issue 7: roll inside and lie flat. How do you choose
- Pyg tutorial (4): Customizing datasets
- Hamming code verification [simple and detailed]
- Excel_ submit
- 使用cell ranger进行单细胞转录组定量分析
- 152-Solana入门(十六)- 创建MetaplexNFT
- [MySQL] database multi table operation customs clearance tutorial (foreign key constraint, multi table joint query)
猜你喜欢

麦克风loading动画效果

156 rust and Solana environment configuration

布隆過濾器

Mysql database foundation: sub query

Weather forecast applet source code / weather wechat applet source code
![Hamming code verification [simple and detailed]](/img/a4/2b1e7977fb0a7bf399a6209165e47d.jpg)
Hamming code verification [simple and detailed]

Candy tunnel JS special effect code

五层参考模型各层总结

Dynamic planning exercises (II)

IDM移动端功能升级说明
随机推荐
数据库与缓存数据一致性问题
Google Earth Engine(GEE)——美国本土岩性数据集
Argo CD 使用
【基于栈的二叉树中序遍历】二叉树的中序遍历+栈,O(h)的空间复杂度
PostgreSQL和MySQL应该如何选择
Eigen common operations
GEO2R:对GEO数据库中的数据进行差异分析
Required Integer parameter ‘XXX‘ is not present
Google Earth Engine(GEE)——全球农田有机土壤碳和氮排放(1992-2018年度)数据集
Yield Guild Games 与 Walken 达成合作
C语言课程设计|学生成绩管理系统(含完整代码)
C语言程序设计——三子棋(学期小作业)
lombok之@NonNull注解
Issue 6: which mainstream programming language should college students choose
Pyg tutorial (1): getting to know pytorch geometry
Pyg tutorial (6): customizing the messaging network
工作那点事
布隆過濾器
數據分析之:不同行業的常見指標
从 Stream 到 Kotlin 再到 SPL
