• 小程序学习一 .json 文件配置


    微信小程序——配置

           以下就是小编对小程序配置的资料进行的系统的整理,希望能对开发者有帮助。

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

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    {
     "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 Array 设置页面路径
    window Object 设置默认页面的窗口表现
    tabBar Object 设置底部 tab 的表现
    networkTimeout Object 设置网络超时时间
    debug Boolean 设置是否开启 debug 模式

    pages

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

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

    如开发目录为:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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 中写

    1
    2
    3
    4
    5
    6
    {
     "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

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

    如 app.json :

    1
    2
    3
    4
    5
    6
    7
    8
    9
    {
     "window":{
      "navigationBarBackgroundColor": "#ffffff",
      "navigationBarTextStyle": "black",
      "navigationBarTitleText": "微信接口功能演示",
      "backgroundColor": "#eeeeee",
      "backgroundTextStyle": "light"
     }
    }

    tabBar

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

    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

    其中 list 接受一个数组,数组中的每个项都是一个对象,其属性值如下:

    属性类型必填说明
    pagePath String 页面路径,必须在 pages 中先定义
    text String tab 上按钮文字
    iconPath String 图片路径,icon 大小限制为40kb
    selectedIconPath String 选中时的图片路径,icon 大小限制为40kb

    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 这个键,如:

    1
    2
    3
    4
    5
    6
    7
    {
     "navigationBarBackgroundColor": "#ffffff",
     "navigationBarTextStyle": "black",
     "navigationBarTitleText": "微信接口功能演示",
     "backgroundColor": "#eeeeee",
     "backgroundTextStyle": "light"
    }
     
     
     
    贴段代码:
    {
      "pages":[
        "pages/index/index",
        "pages/logs/logs"
      ],
      "tabBar": {
        "color":"red",
        "selectedColor":"blue",
        "backgroundColor":"#666",
        "borderStyle":"red",
         "list": [{
          "pagePath": "pages/index/index",
          "text": "首页",
          "iconPath"
          "selectedIconPath"
         }, {
          "pagePath": "pages/logs/logs",
          "text": "日志"
         }]
        },
      "window":{
        "backgroundTextStyle":"light",
        "navigationBarBackgroundColor": "#3a3b3f",
        "navigationBarTitleText": "树懒找房",
        "navigationBarTextStyle":"#fff"
      }
    }
    
     
  • 相关阅读:
    变形金刚还有一个星期!
    SQLSERVER中日期显示样式(网络收集)
    美国《商业周刊》网站提前公布的2007年度世界最有价值品牌
    昨天论文被录 开心
    怎样用javascript操作ftb编辑区内容
    c#中 @的用处
    图片滚动代码。
    一段实现分页的存储过程
    下拉列表控制文本框的个数思路
    什么是ERP (转载自百度知道)
  • 原文地址:https://www.cnblogs.com/allenxieyusheng/p/7680409.html
Copyright © 2020-2023  润新知