• 微信小程序开发之全局配置与页面配置


    目录

    一、全局配置

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

    (2)导航栏  navigationBar

    (3)下拉刷新页面

    (4)上拉触底的距离

    (5)底部导航栏 tabBar

    (5)图标的获取

    二、页面配置

    (1)概念

    (2)页面配置与全局配置的关系

    (3)常用配置项

    三、综合案例

     (1)步骤

     (2)真机调试效果图

     (3) 完整代码


    一、全局配置

    app.json文件就是项目的全局配置文件

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

     


    (2)导航栏  navigationBar

    1)window节点常用配置项

     2)设置导航栏

    • 设置导航栏标题文字

    app.json-->window-->navigationBarTitleText

    • 设置导航栏背景色

    app.json-->window-->navigationBarBackgroundColor

    • 设置导航栏的标题颜色

    app.json-->window-->navigationBarTextStyle

    app.json文件中window节点代码

    1. "window":{
    2. "backgroundTextStyle":"light",
    3. "navigationBarBackgroundColor": "#13227a",
    4. "navigationBarTitleText": "Hello",
    5. "navigationBarTextStyle":"white"
    6. },

     


    (3)下拉刷新页面

    1)概念

    下拉刷新是移动端的转有名词,指的是通过手指在屏幕上的下拉滑动操作,从而重新加载页面数据的行为

    2)设置下拉刷新

    • 开启下拉刷新

    app.json-->window-->enablePullDownRefresh-->true

    • 设置下拉刷新时窗口的背景色

    app.json-->window-->backgroundColor-->指定十六进制的颜色值#efefef

    • 设置下拉刷新时loading样式

    app.json-->window-->backgroundTextStyle-->dark

    1. "window":{
    2. "navigationBarBackgroundColor": "#13227a",
    3. "navigationBarTitleText": "Hello",
    4. "navigationBarTextStyle":"white",
    5. "enablePullDownRefresh": true,
    6. "backgroundColor": "#efefef",
    7. "backgroundTextStyle":"dark"
    8. },

     


    (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节点代码

    1. "tabBar": {
    2. "list": [{
    3. "pagePath": "pages/index/index",
    4. "text": "首页",
    5. "iconPath": "images/home.png",
    6. "selectedIconPath": "images/home-active.png"
    7. },
    8. {
    9. "pagePath": "pages/message/message",
    10. "text": "消息",
    11. "iconPath": "images/message.png",
    12. "selectedIconPath": "images/message-active.png"
    13. },
    14. {
    15. "pagePath": "pages/contract/contract",
    16. "text": "联系我们",
    17. "iconPath": "images/contract.png",
    18. "selectedIconPath": "images/contract-active.png"
    19. }
    20. ]
    21. },

     

    注意事项

    •  可以先在项目的根目录下新建image文件夹,来专门存储项目需要使用到的icon图标
    • 作为tabBar的页面必须放在app.json文件中Pages节点的前面,否则无法正常跳转(切记)


    (5)图标的获取

    博主极力推荐阿里巴巴图库矢量网,免费,且图标丰富,真的很良心的一个实用网站!


    二、页面配置

    (1)概念

    小程序中,每一个页面都有一个属于自己的.json页面配置文件,用来对当前页面的窗口外观、页面效果等进行特定的配置

    (2)页面配置与全局配置的关系

    • app.json中的window节点,可以全局配置小程序中每一个页面的窗口表现
    • 若某个页面想要特殊的窗口外观表现,就可以使用页面级别的.json配置文本进行配置
    • 当全局配置与页面配置冲突时,根据“ 就近原则 ”,会以页面配置为准从而覆盖掉全局配置

    (3)常用配置项

     配置方法与全局配置同理,不再展示。

     


     

    三、综合案例

    本案例是本地生活小程序首页界面的初步实现

     (1)步骤

    • 先配置导航栏效果
    • 配置底部tabBar效果
    • 实现顶部的轮播图
    • 实现九宫格功能框
    • 实现底部图片布局

    (2)真机调试效果图

    (3) 完整代码

    • js文件
    1. // index.js
    2. Page({
    3. data: {
    4. 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:"找装修"}],
    5. },
    6. onLoad:function(options) {
    7. console.log(options)
    8. }
    9. })

    (图片路径需自定义) 

    • json文件
    1. {
    2. "usingComponents": {
    3. "mt-test1":"/components/test/test1"
    4. },
    5. "enablePullDownRefresh": true,
    6. "backgroundColor": "#efefef",
    7. "backgroundTextStyle": "dark"
    8. }

     

    • wxml文件
    1. <swiper indicator-dots indicator-color="white" circular autoplay >
    2. <swiper-item>
    3. <image src="/images/locallife.png" >image>
    4. swiper-item>
    5. <swiper-item>
    6. <image src="/images/locallife2.png">image>
    7. swiper-item>
    8. <swiper-item>
    9. <image src="/images/locallife3.png">image>
    10. swiper-item>
    11. swiper>
    12. <view class="gridList">
    13. <navigator class="gridItem" wx:for="{{image}}" url="/pages/shoplist/shoplist?title={{item.name}}">
    14. <image src="{{item.path}}">image>
    15. <text>{{item.name}}text>
    16. navigator>
    17. view>
    18. <view class="img-box">
    19. <image src="/images/tuijian.png" mode="widthFix">image>
    20. <image src="/images/pingjia.png" mode="widthFix">image>
    21. view>

     

    • wxss文件
    1. swiper {
    2. height: 400rpx;
    3. }
    4. swiper image{
    5. width: 100%;
    6. height: 100%;
    7. }
    8. .gridList{
    9. /* flex布局格式 */
    10. display: flex;
    11. /* 允许自动换行 */
    12. flex-wrap: wrap;
    13. /* 给外层容器左边与上部加上边框线 */
    14. border-left: 1rpx solid #efefef;
    15. border-top: 1rpx solid #efefef;
    16. }
    17. .gridItem{
    18. width: 33.33%;
    19. /* 每个图片的固定高度 */
    20. height: 200rpx;
    21. display: flex;
    22. flex-direction: column;
    23. align-items: center;
    24. justify-content: center;
    25. /* 给内层容器中的每一项加上右侧和底部的边框线 */
    26. border-right: 1rpx solid #efefef;
    27. border-bottom: 1rpx solid #efefef;
    28. /* 改变盒子的方式为border-box */
    29. box-sizing: border-box;
    30. }
    31. .gridItem image{
    32. width: 60rpx;
    33. height: 60rpx;
    34. }
    35. .gridItem text{
    36. font-size: 24rpx;
    37. /* 设置文本与图片的上部距离 */
    38. margin-top: 10rpx;
    39. }
    40. .img-box{
    41. display: flex;
    42. padding: 20rpx 10rpx;
    43. justify-content: space-around;
    44. }
    45. .img-box image{
    46. width: 45%;
    47. }

    都看到这里了,不妨点个赞再溜哈(doge)

  • 相关阅读:
    matlab中图像分割技术之一边缘检测
    分布式事务解决方案
    为了弄清起点小说如何算字扣钱,我特意注册了作家账号
    列表标签(非常重要)
    我的第二本书:Java微服务
    python中protobuf和json互相转换应用
    Vue.js核心技术解析与uni-app跨平台实战开发学习笔记 第5章 Vue.js组件 5.5 Vue获取DOM元素的方法(ref)
    如何将 PDF 转换为 Word:前 5 个应用程序
    数据库主键一定要自增的吗?有哪些场景下不建议自增?
    Spring Boot和Spring有什么区别
  • 原文地址:https://blog.csdn.net/qq_52487066/article/details/125960170