
2.2.1 JSON配置文件
微信默认创建的小程序根目录下包含4个JSON文件,分别是app.json、project.config.json、sitemap.json、index.json,如图2-1所示。下面依次介绍这些文件的作用。

图2-1
1.app.json文件
app.json是微信小程序的全局配置文件,主要用于配置小程序全局性的页面路径、界面表现、网络超时时间、底部tab栏等。默认创建的微信小程序的app.json代码如下。

其中,各部分代码的含义及作用如下。
◆ pages代码表明当前微信小程序由哪些页面组成,其中第一个页面代表当前微信小程序的首页。
◆ window代码用于设置小程序的状态栏、导航条、标题、窗口背景色等。
◆ style代码用于指定使用升级后的WeUI样式。
◆ sitemapLocation用于指明sitemap.json的位置。
app.json的相关配置项如表2-2所示。
表2-2

其中,window的相关属性如表2-3所示。
表2-3

tabBar以及tabBar-list的相关属性如表2-4和表2-5所示。
表2-4

表2-5

networkTimeout的相关属性如表2-6所示。
表2-6

permission以及PermissionObject的相关属性如表2-7和表2-8所示。
表2-7

表2-8

singlePage的相关属性如表2-9所示。
表2-9

2.project.config.json文件
project.config.json是项目配置文件。
3.sitemap.json文件
sitemap.json文件用于配置小程序及其页面是否可被微信索引,文件内容为一个JSON对象。如果没有sitemap.json,则默认为所有页面都允许被索引。
微信现已开放小程序内搜索,开发者可以通过sitemap.json进行配置,或者通过管理后台页面的收录开关来配置其小程序页面是否允许微信索引。当开发者允许微信索引时,微信会通过爬虫的形式,为小程序的页面内容建立索引。当用户的搜索词条触发该索引时,小程序的页面将可能展示在搜索结果中。
爬虫访问小程序内页面时,会携带特定的user-agent:mpcrawler及场景值:1129。需要注意的是,若小程序爬虫发现的页面数据和真实用户的数据呈现不一致,那么该页面将不会进入索引。
4.index.json文件
index.json文件可对index页面的窗口表现进行配置。页面中的配置项在当前页面会覆盖app.json的window中相同的配置项。文件内容为一个JSON对象。
Page的相关配置项以及单页模式的相关属性如表2-10、表2-11所示。
表2-10

表2-11
