当前位置:网站首页>微信小程序开发之全局配置与页面配置
微信小程序开发之全局配置与页面配置
2022-07-25 19:24:00 【Aricl.】
目录
一、全局配置
app.json文件就是项目的全局配置文件

(1)小程序窗口的组成部分

(2)导航栏 navigationBar
1)window节点常用配置项

2)设置导航栏
- 设置导航栏标题文字
app.json-->window-->navigationBarTitleText
- 设置导航栏背景色
app.json-->window-->navigationBarBackgroundColor
- 设置导航栏的标题颜色
app.json-->window-->navigationBarTextStyle
app.json文件中window节点代码
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#13227a",
"navigationBarTitleText": "Hello",
"navigationBarTextStyle":"white"
}, 
(3)下拉刷新页面
1)概念
下拉刷新是移动端的转有名词,指的是通过手指在屏幕上的下拉滑动操作,从而重新加载页面数据的行为
2)设置下拉刷新
- 开启下拉刷新
app.json-->window-->enablePullDownRefresh-->true
- 设置下拉刷新时窗口的背景色
app.json-->window-->backgroundColor-->指定十六进制的颜色值#efefef
- 设置下拉刷新时loading样式
app.json-->window-->backgroundTextStyle-->dark
"window":{
"navigationBarBackgroundColor": "#13227a",
"navigationBarTitleText": "Hello",
"navigationBarTextStyle":"white",
"enablePullDownRefresh": true,
"backgroundColor": "#efefef",
"backgroundTextStyle":"dark"
}, 
(4)上拉触底的距离
1)概念
上拉触底是移动端的专有名词,通过手指在屏幕上的上拉滑动操作,从而加载更多数据的行为
2)设置
app.json-->window-->onReachBottomDistance-->设置新值
注意:小程序默认触底距离为50px,若没有特殊的需求,那么直接使用默认值即可
(5)底部导航栏 tabBar
1)概念
tabBar是移动端应用常见的页面效果,用于实现多页面的快速切换
小程序中tabBar分为两类
- 底部tabBat(常用)
- 顶部tabBar
注意点
- tabBar中只能配置最少2个、最多5个tab页签
- 当渲染顶部tabBar时,不显示icon图标,只显示文本
tabBar的6个组成部分

2)tabBar节点配置项

3)每个tab项的配置选项

4)示例

app.json文件中tabBar节点代码
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "images/home.png",
"selectedIconPath": "images/home-active.png"
},
{
"pagePath": "pages/message/message",
"text": "消息",
"iconPath": "images/message.png",
"selectedIconPath": "images/message-active.png"
},
{
"pagePath": "pages/contract/contract",
"text": "联系我们",
"iconPath": "images/contract.png",
"selectedIconPath": "images/contract-active.png"
}
]
}, 
注意事项
- 可以先在项目的根目录下新建image文件夹,来专门存储项目需要使用到的icon图标
- 作为tabBar的页面必须放在app.json文件中Pages节点的前面,否则无法正常跳转(切记)
(5)图标的获取
博主极力推荐阿里巴巴图库矢量网,免费,且图标丰富,真的很良心的一个实用网站!

二、页面配置
(1)概念
小程序中,每一个页面都有一个属于自己的.json页面配置文件,用来对当前页面的窗口外观、页面效果等进行特定的配置
(2)页面配置与全局配置的关系
- app.json中的window节点,可以全局配置小程序中每一个页面的窗口表现
- 若某个页面想要特殊的窗口外观表现,就可以使用页面级别的.json配置文本进行配置
- 当全局配置与页面配置冲突时,根据“ 就近原则 ”,会以页面配置为准从而覆盖掉全局配置
(3)常用配置项

配置方法与全局配置同理,不再展示。
三、综合案例
本案例是本地生活小程序首页界面的初步实现
(1)步骤
- 先配置导航栏效果
- 配置底部tabBar效果
- 实现顶部的轮播图
- 实现九宫格功能框
- 实现底部图片布局
(2)真机调试效果图

(3) 完整代码
- js文件
// index.js
Page({
data: {
image: [{path:"/images/food.png",name:"吃美食"},{path:"/images/wash.png",name:"约洗浴"},{path:"/images/marry.png",name:"结婚啦"},{path:"/images/KTV.png",name:"去唱歌"},{path:"/images/work.png",name:"找工作"},{path:"/images/teacher.png",name:"报辅导"},{path:"/images/car.png",name:"养汽车"},{path:"/images/hotel.png",name:"定酒店"},{path:"/images/fush.png",name:"找装修"}],
},
onLoad:function(options) {
console.log(options)
}
})
(图片路径需自定义)
- json文件
{
"usingComponents": {
"mt-test1":"/components/test/test1"
},
"enablePullDownRefresh": true,
"backgroundColor": "#efefef",
"backgroundTextStyle": "dark"
}
- wxml文件
<!-- 首页顶部的轮播图效果 -->
<swiper indicator-dots indicator-color="white" circular autoplay >
<swiper-item>
<image src="/images/locallife.png" ></image>
</swiper-item>
<swiper-item>
<image src="/images/locallife2.png"></image>
</swiper-item>
<swiper-item>
<image src="/images/locallife3.png"></image>
</swiper-item>
</swiper>
<!-- 九宫格功能区 -->
<!-- 外层容器 -->
<view class="gridList">
<!-- 内层容器 -->
<navigator class="gridItem" wx:for="{
{image}}" url="/pages/shoplist/shoplist?title={
{item.name}}">
<image src="{
{item.path}}"></image>
<text>{
{item.name}}</text>
</navigator>
</view>
<!-- 底部图片功能块 -->
<view class="img-box">
<image src="/images/tuijian.png" mode="widthFix"></image>
<image src="/images/pingjia.png" mode="widthFix"></image>
</view>
- wxss文件
swiper {
height: 400rpx;
}
swiper image{
width: 100%;
height: 100%;
}
.gridList{
/* flex布局格式 */
display: flex;
/* 允许自动换行 */
flex-wrap: wrap;
/* 给外层容器左边与上部加上边框线 */
border-left: 1rpx solid #efefef;
border-top: 1rpx solid #efefef;
}
.gridItem{
width: 33.33%;
/* 每个图片的固定高度 */
height: 200rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
/* 给内层容器中的每一项加上右侧和底部的边框线 */
border-right: 1rpx solid #efefef;
border-bottom: 1rpx solid #efefef;
/* 改变盒子的方式为border-box */
box-sizing: border-box;
}
.gridItem image{
width: 60rpx;
height: 60rpx;
}
.gridItem text{
font-size: 24rpx;
/* 设置文本与图片的上部距离 */
margin-top: 10rpx;
}
.img-box{
display: flex;
padding: 20rpx 10rpx;
justify-content: space-around;
}
.img-box image{
width: 45%;
}
都看到这里了,不妨点个赞再溜哈(doge)
边栏推荐
- iMeta | Sangerbox: 交互式整合临床生信分析平台
- 微信小程序 27 进度条的动态实现和搜索框、热搜榜的静态搭建
- Hongmeng - Damiao computing Sketchpad - VIDEO
- 新瓶装老酒--近期APT32(海莲花)组织攻击活动样本分析
- 鸿蒙-大喵计算画板-简介
- 微信小程序 28 热搜榜的完善①
- Use of swift basic codable (jsonencoder jsondecoder)
- 基于PHP的中非南南合作信息交流平台网站建设
- Imperial cms7.5 imitation "question and answer library" question and answer learning platform website source code with mobile version
- CLIP还能做分割任务?哥廷根大学提出一个使用文本和图像prompt,能同时作三个分割任务的模型CLIPSeg,榨干CLIP能力...
猜你喜欢

【DETR用于3D目标检测】3DETR: An End-to-End Transformer Model for 3D Object Detection
![[iniparser] simple use of the project configuration tool iniparser](/img/2b/1d20b4ef44dfe2544891d9c72b676e.png)
[iniparser] simple use of the project configuration tool iniparser

Sccm2012r2 network deployment reinstallation system

Full scale and Xuan of C key

【919. 完全二叉树插入器】

Pymoo学习 (5):收敛性分析

iMeta | Sangerbox: 交互式整合临床生信分析平台

Improvement of wechat applet 28 hot search list ①

【刷题记录】21. 合并两个有序链表

常用的开发软件下载地址
随机推荐
前夕 - 0day威胁情报
微信小程序10-微搭模板
Youth, oh, youth
Fearless of high temperature and rainstorm, how can Youfu network protect you from worry?
JS learning notes 16: switching pictures small project practice
英诚医院内部网络规划与设计
How many lines of code is appropriate for a function? Clean Code
HTTP cache tongtianpian, there may be something you want
QT compiled successfully, but the program could not run
[919. Complete binary tree inserter]
伺服驱动器在机器人上的研究与应用
【919. 完全二叉树插入器】
阿里云免费SSL证书申请详细流程
这种动态规划你见过吗——状态机动态规划之股票问题(上)
[applet development] detailed explanation of host environment
Empire CMS whole station | mobile number /qq lianghao mall source code | suitable for mobile terminal
Wechat campus maintenance application applet graduation design finished product of applet completion work (3) background function
小程序毕设作品之微信校园维修报修小程序毕业设计成品(5)任务书
I3 status configuration
600000 pieces of data are made from March 1 to March 31. Videodate requires starting time from 00:00 to 24:00 on March 1 to 31, which is only for notes