小程序API能力汇总——基础容器API(一)

ty.getEnterOptions

获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

复制代码
/**
 * 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与App.onLaunch的回调参数一致;如果当前是热启动,则返回值与App.onShow 一致。
 */
export function getEnterOptions(params?: {
  complete?: () => void;
  success?: (params: {
    /** 启动小程序的路径 (代码包路径) */
    path: string;
    /** 启动小程序的 query 参数 */
    query: Record<string, any>;
    /** 分享转发 */
    referrerInfo: ReferrerInfo;
    /** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */
    apiCategory?: string;
  }) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.getEnterOptionsSync

获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。同步方法

需引入MiniKit,且在>=2.0.0版本才可使用

ty.getEnterOptions 的同步版本

返回值

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

函数定义示例

复制代码
/**
 * 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与App.onLaunch的回调参数一致;如果当前是热启动,则返回值与App.onShow 一致。
 */
export function getEnterOptionsSync(): {
  /** 启动小程序的路径 (代码包路径) */
  path: string;
  /** 启动小程序的 query 参数 */
  query: Record<string, any>;
  /** 分享转发 */
  referrerInfo: ReferrerInfo;
  /** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */
  apiCategory?: string;
};

ty.getLaunchOptions

获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

复制代码
/**
 * 获取小程序启动时的参数。与App.onLaunch的回调参数一致。
 */
export function getLaunchOptions(params?: {
  complete?: () => void;
  success?: (params: {
    /** 启动小程序的路径 (代码包路径) */
    path: string;
    /** 启动小程序的 query 参数 */
    query: Record<string, any>;
    /** 分享转发 */
    referrerInfo: ReferrerInfo;
    /** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */
    apiCategory?: string;
  }) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.getLaunchOptionsSync

获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。同步方法

需引入MiniKit,且在>=2.0.0版本才可使用

ty.getLaunchOptions 的同步版本

返回值

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

函数定义示例

复制代码
/**
 * 获取小程序启动时的参数。与App.onLaunch的回调参数一致。
 */
export function getLaunchOptionsSync(): {
  /** 启动小程序的路径 (代码包路径) */
  path: string;
  /** 启动小程序的 query 参数 */
  query: Record<string, any>;
  /** 分享转发 */
  referrerInfo: ReferrerInfo;
  /** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */
  apiCategory?: string;
};

ty.getAppInfo

拿到当前 App 的业务信息

需引入BizKit,且在>=3.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
serverTimestamp number 云端时间戳
appVersion string app 版本
language string 语言
countryCode string 国家码
regionCode string 地区码
appName string appName app 名称
appIcon string appIcon app 图标
appEnv number app 环境 0: 日常 1: 预发 2: 线上
appBundleId string app 包名
appScheme string app scheme

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

ty.getAppInfo

拿到当前 App 的业务信息

需引入BizKit,且在>=3.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
serverTimestamp number 云端时间戳
appVersion string app 版本
language string 语言
countryCode string 国家码
regionCode string 地区码
appName string appName app 名称
appIcon string appIcon app 图标
appEnv number app 环境 0: 日常 1: 预发 2: 线上
appBundleId string app 包名
appScheme string app scheme

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

ty.getTempDirectory

获取通用缓存路径

需引入BaseKit,且在>=2.2.3版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
tempDirectory string 【待废弃, 不建议使用】临时文件夹路径

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

复制代码
/**
 * 获取通用缓存路径
 */
export function getTempDirectory(params?: {
  complete?: () => void;
  success?: (params: {
    /** 【待废弃, 不建议使用】临时文件夹路径 */
    tempDirectory: string;
  }) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.getMenuButtonBoundingClientRect

获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。

需引入MiniKit,且在>=2.3.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性 类型 说明
width number 宽度,单位:px
height number 高度,单位:px
top number 上边界坐标,单位:px
right number 右边界坐标,单位:px
bottom number 下边界坐标,单位:px
left number 左边界坐标,单位:px

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

复制代码
/**
 * 获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。
 */
export function getMenuButtonBoundingClientRect(params?: {
  complete?: () => void;
  success?: (params: {
    /** 宽度,单位:px */
    width: number;
    /** 高度,单位:px */
    height: number;
    /** 上边界坐标,单位:px */
    top: number;
    /** 右边界坐标,单位:px */
    right: number;
    /** 下边界坐标,单位:px */
    bottom: number;
    /** 左边界坐标,单位:px */
    left: number;
  }) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.getMenuButtonBoundingClientRectSync

获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。同步方法

需引入MiniKit,且在>=2.3.0版本才可使用

ty.getMenuButtonBoundingClientRect 的同步版本

返回值

属性 类型 说明
width number 宽度,单位:px
height number 高度,单位:px
top number 上边界坐标,单位:px
right number 右边界坐标,单位:px
bottom number 下边界坐标,单位:px
left number 左边界坐标,单位:px

函数定义示例

复制代码
/**
 * 获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。
 */
export function getMenuButtonBoundingClientRectSync(): {
  /** 宽度,单位:px */
  width: number;
  /** 高度,单位:px */
  height: number;
  /** 上边界坐标,单位:px */
  top: number;
  /** 右边界坐标,单位:px */
  right: number;
  /** 下边界坐标,单位:px */
  bottom: number;
  /** 左边界坐标,单位:px */
  left: number;
};

👉 立即开发

相关推荐
海兰2 小时前
【文字三国志:第六篇】天命重构,UI组件设计细节
人工智能·ui·语言模型·小程序
Alan_753 小时前
并发接口调用稳定性优化:特征隔离与流量整形实操
api
草根站起来5 小时前
微信小程序request net:ERR_CERT_DATE_INVALID
微信小程序·小程序
小北的AI科技分享7 小时前
广州小程序平台推荐:2026年本地商家数字化选型深度测评
小程序·广州小程序平台
MageGojo8 小时前
10 种主题随机诗词:一个 API 解决小程序的诗词内容源
python·小程序·古诗词·api 接入
青山科技分享8 小时前
2026北京小程序平台推荐——本地商家数字化选型全维度解析
小程序·小程序平台推荐
Resistance丶未来9 小时前
魔芋 AI 企业级大模型落地实战指南
人工智能·api·claude·gemini·deepseek·魔芋ai·魔芋api
私人珍藏库20 小时前
【Android】Soul v5.86.0 内置模块版
android·app·工具·软件·多功能
肖有米XTKF864621 小时前
肖有米团队开发:青蓝山泉送水模式系统
小程序·团队开发·零售·csdn开发云
向量引擎1 天前
向量引擎API中转站深度测评:如何实现低成本、高并发的向量检索
人工智能·gpt·aigc·api·ai编程