小程序配置项

142 阅读2分钟

json 语法注意

小程序的 json 是严格版的语法,需要注意以下问题:

  1. 不能写注释。
  2. 同级数据最后一项不允许多余的逗号。
  3. 字符串和键名称只能使用 双引号。
  4. 布尔类型值,数字类型值 就 不能带引号。

app.json 全局配置项

小程序根目录下的 app.json 文件用来对微信小程序进行全局配置

决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。

常用配置项 - 重点

配置项功能备注
"pages":[]页面文件的路径用户默认打开数组的第一项 (启动页)
"window":{}窗口表现原生微信 App 的头部,性能很好,但是修改也会有限制。
"tabBar":{ "list": [ ] }多 tab 页面切换只能配置最少 2 个、最多 5 个 tab

注意事项

  1. pages添加页面配置后,微信开发工具会自动增量新建对应的 wxml,wxss,js,json 文件,如果新建错误需要手动删除。
  2. 小程序的界面中,背景默认在页面后面,需要下拉后才能看到背景部分。
  3. 通过 window"enablePullDownRefresh": true 开启页面下拉功能。

参考代码

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs",
    "pages/demo01/index",
    "pages/demo02/index",
    "pages/demo03/index",
    "pages/demo04/index"
  ],
  "window":{
    "enablePullDownRefresh":true,
    "backgroundTextStyle":"dark",
    "backgroundColorTop":"#F4B096",
    "backgroundColor":"#f00",
    "pageOrientation":"portrait",
    "navigationBarBackgroundColor": "#00B26A",
    "navigationBarTitleText": "铁头娃",
    "navigationBarTextStyle":"white",
    "navigationStyle":"default"
  },
  "tabBar": {
    "color": "#585858",
    "selectedColor": "#E74C57",
    "backgroundColor":"#FFF",
    "position":"bottom",
    "borderStyle":"black",
    "custom":false,
    "list":[
      {
        "pagePath": "pages/demo01/index",
        "text": "第一页",
        "iconPath": "../images/tabs/index.png",
        "selectedIconPath": "../images/tabs/index_selected.png"
      },
      {
        "pagePath": "pages/demo02/index",
        "text": "第二页",
        "iconPath": "../images/tabs/cart.png",
        "selectedIconPath": "../images/tabs/cart_selected.png"
      },
      {
        "pagePath": "pages/demo03/index",
        "text": "第三页",
        "iconPath": "../images/tabs/category.png",
        "selectedIconPath": "../images/tabs/category_selected.png"
      },
      {
        "pagePath": "pages/demo04/index",
        "text": "第四页",
        "iconPath": "../images/tabs/user.png",
        "selectedIconPath": "../images/tabs/user_selected.png"
      }
    ]
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}

更多配置参考