跳至主要內容

常用其他全局配置

刘春龙原创...大约 2 分钟WEB前端小程序教程文档

小程序根目录下的 app.json 文件用来对微信小程序进行其他全局配置。文件内容为一个 JSON 对象

属性类型必填描述
stylestring指定使用升级后的 weui 样式
sitemapLocationstring指明 sitemap.json 的位置
networkTimeoutObject网络超时时间
debugboolean是否开启 debug 模式,默认关闭
debugOptionsObject调试相关配置
permissionObject小程序接口权限相关设置
............
{
  "entryPagePath": "pages/index/index",
  "pages": [
    "pages/news/news",
    "pages/index/index",
    "pages/logs/logs",
    "pages/about/about"
  ],
  "window": {
    "navigationBarBackgroundColor": "#000000",
    "navigationBarTextStyle": "white",
    "navigationBarTitleText": "第一个小程序",
    "backgroundColor": "#000000",
    "backgroundTextStyle": "light",
    "enablePullDownRefresh": true,
    "onReachBottomDistance": 50
  },
  "tabBar": {
    "color": "#999999",
    "selectedColor": "#ff0000",
    "backgroundColor": "#fff",
    "borderStyle": "black",
    "position": "bottom",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页",
        "iconPath": "./images/home.png",
        "selectedIconPath": "./images/home_select.png"
      },
      {
        "pagePath": "pages/news/news",
        "text": "新闻",
        "iconPath": "./images/news.png",
        "selectedIconPath": "./images/news_select.png"
      }
    ]
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json",
  "networkTimeout": {
    "request": 10000,
    "downloadFile": 10000
  },
  "debug": true,
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序位置接口的效果展示"
    }
  },
  "debugOptions": {
    "enableFPSPanel": true
  }
}

style

微信客户端 7.0 开始,UI 界面进行了大改版。小程序也进行了基础组件的样式升级。app.json 中配置 "style": "v2"可表明启用新版的组件样式

sitemapLocation

指明 sitemap.json的位置;默认为 'sitemap.json' 即在 app.json 同级目录下名字的 sitemap.json 文件

networkTimeout

各类网络请求的超时时间,单位均为毫秒

属性类型必填默认值说明
requestnumber60000wx.request 的超时时间,单位:毫秒
connectSocketnumber60000wx.connectSocket 的超时时间,单位:毫秒
uploadFilenumber60000wx.uploadFile 的超时时间,单位:毫秒
downloadFilenumber60000wx.downloadFile 的超时时间,单位:毫秒

debug

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

debugOptions

小程序调试相关配置项

属性类型必填默认值描述
enableFPSPanelbooleanfalse是否开启 FPS 面板

FPS 面板

为了便于开发者调试渲染层的交互性能,小程序基础库提供了选项开启 FPS 面板,开发者可以实时查看渲染层帧率

开启方式

"debugOptions": {
  "enableFPSPanel": true
}

提示

必须在真机上才能看到

permission

小程序接口权限相关设置

例如:小程序定位设置,配置如下

"permission": {
  "scope.userLocation": {
    "desc": "你的位置信息将用于小程序位置接口的效果展示"
   }
}
上次编辑于:
贡献者: 刘春龙
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.7