1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-13 00:50:40 +08:00
Files
2026-08-31 07:58:23 +08:00

8.1 KiB
Raw Permalink Blame History

UniApp API 参考文档

本文档提供 uni-app 所有 API 的完整参考信息。

API 分类索引

1. 网络请求(Network

2. 数据存储(Storage

3. 设备信息(Device

4. 界面交互(UI

5. 位置服务(Location

6. 媒体处理(Media

7. 页面路由(Navigation

  • uni.navigateTo - 保留当前页面,跳转到应用内的某个页面
  • uni.redirectTo - 关闭当前页面,跳转到应用内的某个页面
  • uni.reLaunch - 关闭所有页面,打开到应用内的某个页面
  • uni.switchTab - 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  • uni.navigateBack - 关闭当前页面,返回上一页面或多级页面

8. 文件操作(File

9. 支付(Payment

10. 分享(Share

11. 其他 APIOther

API 调用规范

回调函数

uni-app API 支持两种调用方式:

  1. 回调函数方式
uni.request({
  url: 'https://api.example.com/data',
  success: (res) => {
    console.log(res.data)
  },
  fail: (err) => {
    console.error(err)
  }
})
  1. Promise 方式(部分 API 支持):
uni.request({
  url: 'https://api.example.com/data'
}).then(res => {
  console.log(res.data)
}).catch(err => {
  console.error(err)
})

同步 API

部分 API 提供同步版本(以 Sync 结尾),如:

  • uni.getStorageSync() - 同步获取存储
  • uni.setStorageSync() - 同步设置存储
  • uni.getSystemInfoSync() - 同步获取系统信息

平台兼容性

每个 API 的详细平台支持情况见对应 API 的文档。使用前请检查平台兼容性,必要时使用条件编译:

// #ifdef MP-WEIXIN
uni.requestPayment({
  // 微信小程序支付
})
// #endif

// #ifdef APP-PLUS
uni.requestPayment({
  // App 支付
})
// #endif

参考资源