小程序开放平台

文档中心
小组件配置
全局配置
页面配置
框架接口
XHSML 语法参考

小组件全局配置

开发
>
框架
>
小组件配置
>
全局配置
>
更新时间:2025-08-04 20:32:03

小组件根目录下的

app.json
文件用来对小红书小组件进行全局配置。文件内容为一个 JSON 对象,有以下属性:

配置项

属性
类型
必填
描述
pagesstring页面路径列表
windowObject全局的默认窗口表现
networkTimeoutObject网络超时时间
permissionObject小组件接口权限相关设置
usingComponentsObject全局自定义组件配置

pages

用于指定小组件由哪些页面组成,每一项都对应一个页面的 路径(含文件名) 信息。文件名不需要写文件后缀,框架会自动去寻找对应位置的

.json
,
.js
,
.xhsml
,
.css
四个文件进行处理。

由于小组件只支持一个页面,数组的第一项代表小组件的唯一可用页面。

目录示例:

├── app.js
├── app.json
├── app.css
├── pages
│   │── index
│        ├── index.xhsml
│        ├── index.js
│        ├── index.json
│        └── index.css
│   
└── utils

window

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

属性
类型
默认值
描述
navigationBarBackgroundColorHexColor#000000导航栏背景颜色,如 #000000
navigationBarTextStylestringwhite导航栏标题颜色,仅支持 black / white
navigationBarTitleTextstring导航栏标题文字内容
navigationStylestringdefault导航栏样式,仅支持以下值:
default 默认样式
custom 自定义导航栏,只保留右上角胶囊按钮。
backgroundColorHexColor#ffffff窗口的背景色
enablePullDownRefreshbooleanfalse是否开启全局的下拉刷新。
onReachBottomDistancenumber50页面上拉触底事件触发时距页面底部距离,单位为 px
  • 注 1:HexColor(十六进制颜色值),如"#ff00ff"

如:

{
  "window": {
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "导航title",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"
  }
}

networkTimeout

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

属性
类型
必填
默认值
说明
requestnumber60000xhs.request 的超时时间,单位:毫秒。
connectSocketnumber60000xhs.connectSocket 的超时时间,单位:毫秒。
uploadFilenumber60000xhs.uploadFile 的超时时间,单位:毫秒。
downloadFilenumber60000xhs.downloadFile 的超时时间,单位:毫秒。

permission

小组件接口权限相关设置。字段类型为 Object,结构为:

属性
类型
必填
默认值
描述
scope.userLocationPermissionObject位置相关权限声明

PermissionObject 结构

属性
类型
必填
默认值
描述
descstring小组件获取权限时展示的接口用途说明。最长 30 个字符

如:

{
  "pages": ["pages/index/index"],
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小组件位置接口的效果展示" // 高速公路行驶持续后台定位
    }
  }
}

usingComponents

在此处声明的自定义组件视为全局自定义组件,在小组件内的页面或自定义组件中可以直接使用而无需再声明。