Detailed explanation of the JSON configuration file with json suffix in the code composition of the mini program

php是最好的语言
Release: 2018-07-28 09:56:03
Original
2982 people have browsed it

WeChat applet code consists of the following four types of files:

  1. .json suffixed JSON configuration file

  2. .wxml suffixed WXML template file

  3. wxss suffixed WXSS style file

  4. .js suffixed JS script Logical file

1. JSON configuration

We can see that there is an app.json and project.config.json in the root directory of the project, and in pages/logs There is also a logs.json in the directory. Let's explain their uses in turn.

Mini program configuration app.json

app.json is the global configuration of the current mini program, including all page paths of the mini program , interface performance, network timeout, bottom tab, etc. The app.json configuration content in the QuickStart project is as follows:

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle":"black"
  }
}
Copy after login

Let’s briefly talk about the meaning of each item in this configuration:

  1. pages field - used to describe the current page The path of all pages of the program. This is to let the WeChat client know in which directory your mini program page is currently defined.

  2. window field - the top background color and text color of all pages of the mini program are defined here.

Tool configuration project.config.json

Usually when everyone uses a tool, they will focus on their own preferences Make some personalized configurations, such as interface color, compilation configuration, etc. When you change to another computer and reinstall the tool, you will have to reconfigure it.

Considering this, the mini program developer tool will generate a project.config.json in the root directory of each project. Any configuration you make on the tool will be written to this file. When you restart When installing tools or changing computers to work, you only need to load the code package of the same project, and the developer tools will automatically help you restore the personalized configuration when you were developing the project, including the color of the editor and the time when the code was uploaded. Automatic compression and a range of options.

Page configuration page.json

The page.json here is actually used to represent the logs.json in the pages/logs directory. Configuration related to the mini program page.

If the style of your entire mini program is blue, then you can declare that the top color is blue in app.json. The actual situation may not be like this. Maybe each page in your mini program has a different color tone to distinguish different functional modules. Therefore, we provide page.json so that developers can independently define some attributes of each page, such as just now Talk about the top color, whether to allow pull-down refresh, etc.

Configuration details

app.json file is used to globally configure the WeChat applet, determine the path of the page file, window performance, set the network timeout, and set more tab etc.

The following is an app.json that contains all configuration options:

{
  "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
}
Copy after login

app.json configuration item list

Attributes type Required describe
pages String Array yes Set page path
window Object no Set the window performance of the default page
tabBar Object no Set the performance of the bottom tab
networkTimeout Object no Set network timeout
debug Boolean no Set whether to enable debug mode

pages

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

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

如开发目录为:

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 中写

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ]
}
Copy after login

window

用于设置小程序的状态栏、导航条、标题、窗口背景色。

属性 类型 默认值 描述 最低版本
navigationBarBackgroundColor HexColor #000000 导航栏背景颜色,如"#000000"
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white
navigationBarTitleText String 导航栏标题文字内容
navigationStyle String default 导航栏样式,仅支持 default/custom。custom 模式可自定义导航栏,只保留右上角胶囊状的按钮 微信版本 6.6.0
backgroundColor HexColor #ffffff 窗口的背景色
backgroundTextStyle String dark 下拉 loading 的样式,仅支持 dark/light
backgroundColorTop String #ffffff 顶部窗口的背景色,仅 iOS 支持 微信版本 6.5.16
backgroundColorBottom String #ffffff 底部窗口的背景色,仅 iOS 支持 微信版本 6.5.16
enablePullDownRefresh Boolean false 是否开启下拉刷新,详见页面相关事件处理函数
onReachBottomDistance Number 50 页面上拉触底事件触发时距页面底部距离,单位为px

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

注:navigationStyle 只在 app.json 中生效。开启 custom 后,低版本客户端需要做好兼容。开发者工具基础库版本切到 1.7.0(不代表最低版本,只供调试用) 可方便切到旧视觉

如 app.json :

{
  "window":{
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "微信接口功能演示",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"
  }
}
Copy after login

tabBar

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

Tip:

  1. 当设置 position 为 top 时,将不会显示 icon

  2. tabBar 中的 list 是一个数组,只能配置最少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
position String bottom 可选值 bottom、top

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

属性 类型 必填 说明
pagePath String 页面路径,必须在 pages 中先定义
text String tab 上按钮文字
iconPath String 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPath String 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

networkTimeout

可以设置各种网络请求的超时时间。

属性说明:

属性 类型 必填 说明
request Number wx.request的超时时间,单位毫秒,默认为:60000
connectSocket Number wx.connectSocket的超时时间,单位毫秒,默认为:60000
uploadFile Number wx.uploadFile的超时时间,单位毫秒,默认为:60000
downloadFile Number wx.downloadFile的超时时间,单位毫秒,默认为:60000

debug

可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息有Page的注册页面路由数据更新事件触发 。 可以帮助开发者快速定位一些常见的问题。

page.json

每一个小程序页面也可以使用.json文件来对本页面的窗口表现进行配置。 页面的配置比app.json全局配置简单得多,只是设置 app.json 中的 window 配置项的内容,页面中配置项会覆盖 app.json 的 window 中相同的配置项。

页面的.json只能设置 window 相关的配置项,以决定本页面的窗口表现,所以无需写 window 这个键,如:

属性 类型 默认值 描述
navigationBarBackgroundColor HexColor #000000 导航栏背景颜色,如"#000000"
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white
navigationBarTitleText String 导航栏标题文字内容
backgroundColor HexColor #ffffff 窗口的背景色
backgroundTextStyle String dark 下拉 loading 的样式,仅支持 dark/light
enablePullDownRefresh Boolean false 是否开启下拉刷新,详见页面相关事件处理函数。
disableScroll Boolean false 设置为 true 则页面整体不能上下滚动;只在 page.json 中有效,无法在 app.json 中设置该项
onReachBottomDistance Number 50 页面上拉触底事件触发时距页面底部距离,单位为px
{
  "navigationBarBackgroundColor": "#ffffff",
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "微信接口功能演示",
  "backgroundColor": "#eeeeee",
  "backgroundTextStyle": "light"
}
Copy after login

相关文章:

微信小程序 教程之小程序配置    

微信小程序的配置

相关视频:

App.json全局配置文件详解-微信小程序开发视频教程

The above is the detailed content of Detailed explanation of the JSON configuration file with json suffix in the code composition of the mini program. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!