微信小程序学习笔记(一)——三类配置文件(app.json、页面名.json、sitemap.json)

文章目录

  • 1. 全局配置文件(app.json)
    • 1.1 page
    • 1.2 window
      • 1.2.1 backgroundTextStyle
      • 1.2.2 navigationBarBackgroundColor
      • 1.2.3 navigationBarTitleText
      • 1.2.4 navigationBarTextStyle
      • 1.2.5 enablePullDownRefresh
      • 1.2.6 backgroundColor
      • 1.2.7 其余属性
    • 1.3 tabBar
      • 1.3.1 list
        • 1.3.1.1 pagePath
        • 1.3.1.2 text
        • 1.3.1.3 iconPath
        • 1.3.1.4 selectedIconPath
      • 1.3.2 color
      • 1.3.3 selectedColor
      • 1.3.4 backgroundColor
      • 1.3.5 position
  • 2. 页面配置文件(页面名.json)
    • 2.1 配置项
  • 3. sitemap.json 配置文件

1. 全局配置文件(app.json)

1.1 page

类型:string[]
必填:
描述:用于指定小程序由哪些页面组成,每一项都对应一个页面的路径(含文件名)信息。文件名不需要写文件后缀,框架会自动去寻找对应位置的 .json, .js, .wxml, .wxss 四个文件进行处理。

"pages":[
    "pages/index/index",
    "pages/logs/logs"
  ]

数组的第一项代表小程序的初始页面(首页)。小程序中新增、减少页面,都需要对 pages 数组进行修改。

"pages":[
	"pages/demo1/demo1",
    "pages/index/index",
    "pages/logs/logs"
  ]

微信开发者工具中编辑并保存后,会自动在 pages 文件夹下创建 demo1 相关的文件。若要编译后首先显示的是 demo1 页面而不是 index 页面,只需将 “pages/demo1/demo1” 放在 index 上面即可。

1.2 window

类型:Object
必填:
描述:用于设置小程序的状态栏、导航条、标题、窗口背景色。

"window":{
   "backgroundTextStyle": "dark",
    "navigationBarBackgroundColor": "#0094ff",
    "navigationBarTitleText": "我的应用",
    "navigationBarTextStyle": "white",
    "enablePullDownRefresh": true,
    "backgroundColor": "yellow"
  }

1.2.1 backgroundTextStyle

下拉 loading (会出现三个小圆点)的样式,仅支持 dark / light。

1.2.2 navigationBarBackgroundColor

导航栏背景颜色。

1.2.3 navigationBarTitleText

导航栏标题文字内容。

1.2.4 navigationBarTextStyle

导航栏标题颜色,仅支持 black / white。

1.2.5 enablePullDownRefresh

是否开启全局的下拉刷新。

1.2.6 backgroundColor

窗口的背景色。(不是页面颜色,下拉时会显示出背景色

1.2.7 其余属性

可以查询官方文档:Window 中的属性

1.3 tabBar

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

"tabBar": {
    "list": [{
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "icon/_home.png",
      "selectedIconPath": "icon/home.png"
    },
    {
      "pagePath": "pages/img/img",
      "text": "图片",
      "iconPath": "icon/_img.png",
      "selectedIconPath": "icon/img.png"
    }],
    "color": "#0094ff",
    "selectedColor": "#ff9400",
    "backgroundColor": "#ff5533",
    "position": "top"
  }

微信小程序学习笔记(一)——三类配置文件(app.json、页面名.json、sitemap.json)_第1张图片

1.3.1 list

类型:Array
必填:
描述:tab 的列表,最少 2 个,最多 5 个 tab。

1.3.1.1 pagePath

页面路径,必须在 pages 中先定义,之后才能在这里使用。

1.3.1.2 text

tab 上的按钮文字。

1.3.1.3 iconPath

图片路径,icon 大小限制为 40kb。当 positiontop 时,不显示 icon。

1.3.1.4 selectedIconPath

选中时的图片路径,icon 大小限制为 40kb。当 positiontop 时,不显示 icon。

1.3.2 color

必填:
描述:tab 上的文字默认颜色,仅支持十六进制颜色

1.3.3 selectedColor

必填:
描述:tab 上的文字选中时的颜色,仅支持十六进制颜色

1.3.4 backgroundColor

必填:
描述:tab 的背景色,仅支持十六进制颜色

1.3.5 position

必填:
默认值:bottom
描述:tabBar 的位置,仅支持 bottom / top。

2. 页面配置文件(页面名.json)

每一个小程序页面也可以使用 .json 文件来对本页面的窗口表现进行配置。页面中的配置项在当前页面会覆盖 app.json 的 window 中相同的配置项。

2.1 配置项

官方文档:页面配置

3. sitemap.json 配置文件

可以在其中配置页面是否允许用户使用微信索引。
允许,则当用户的搜索词条触发该索引时,可以将页面显示在搜索结果中。

你可能感兴趣的:(微信小程序)