微信小程序app.json配置文件的主要配置项

366 阅读2分钟

app.json配置文件中主要的配置文件有

官方文档

  1. pages:页面或组件路径列表。
  2. entryPagePath:默认启动页面路径列表。
  3. tabBar:底部tab栏路径和配置。 详细
  4. usingComponents:注册自定义组件。
  5. window:全局默认窗口的配置。 详细
  6. style:指定使用升级后的weui样式,如v2。
  7. resolveAlias:自定义模块映射规则。如"resolveAlias": {"@/*": "/*"}
    其中的 key 和 value 须以 /* 结尾
  8. onReachBottomDistance:页面上拉触底事件触发时距页面底部距离,单位为px。默认50。

1.pages

用于指定小程序由哪些页面组成,每一项都对应一个页面的 路径(含文件名) 信息。文件名不需要写文件后缀。小程序中新增/减少页面,都需要对 pages 数组进行修改。

  • 以数组形式编写,每一个元素都是页面或组件的路径地址。
  • 在pages中填写的路径如没有对应的文件则会自动创建pages页面。不删除pages中的路径删除文件夹后也会自动创建回来。
  "pages": [
    "pages/index/index",
    "pages/category/category",
    "pages/cart/cart",
    "pages/profile/profile",
    "pages/market/market",
  ]

2.entryPagePath

指定小程序的默认启动路径(首页),常见情景是从微信聊天列表页下拉启动、小程序列表启动等。如果不填,将默认为 pages 列表的第一项。

    "entryPagePath": "pages/index/index",

3.tabBar

如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。
其中 list 接受一个数组,只能配置最少 2 个、最多 5 个 tab。tab 按数组的顺序排序,每个项都是一个对象。

"tabBar": {
    "color": "#000000",
    "selectedColor": "#f3514f",
    "list": [{
        "pagePath": "pages/index/index",
        "text": "主页",
        "iconPath": "/assets/主页.png",
        "selectedIconPath": "/assets/主页 (1).png"
      },
      {
        "pagePath": "pages/category/category",
        "text": "分类",
        "iconPath": "/assets/分类.png",
        "selectedIconPath": "/assets/分类 (1).png"
      },
    ]
  }

4.usingComponents

全局自定义组件配置

  "usingComponents": {
    "customCheckbox": "/components/customCheckbox/customCheckbox",
    "custom2": "/components/custom2/custom",
    "customStore": "/components/customStore/customStore",
    "customComputed": "/components/customComputed/customComputed",
    "customWatch": "/components/customWatch/customWatch",
    "van-image": "@vant/weapp/image/index",
    "van-button": "@vant/weapp/button/index"
  }

5.window

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

  "window": {
    "navigationBarTitleText": "花城",
    "navigationBarTextStyle": "white",
    "navigationBarBackgroundColor": "#f3514f",
    "enablePullDownRefresh": true,
    "backgroundColor": "#efefef"
  }