
Uniapp Cloud
- 20 installs
- 5 repo stars
- Updated July 29, 2026
- full-statck-skills/uniapp-skills
Use uniCloud in uni-app for cloud database CRUD, cloud functions, storage, and datacom components with permission setup.
About
Guides uniCloud cloud development in uni-app, covering project setup, cloud database CRUD, cloud functions, storage, and datacom components. A developer uses it to add serverless backend services to a uni-app project.
- Work with cloud databases and cloud functions
- Set up uniCloud project, storage, and permissions
Uniapp Cloud by the numbers
- 20 all-time installs (skills.sh)
- Ranked #3,455 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/uniapp-skills --skill uniapp-cloudAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 20 |
|---|---|
| repo stars | ★ 5 |
| Last updated | July 29, 2026 |
| Repository | full-statck-skills/uniapp-skills ↗ |
What it does
Use uniCloud in uni-app for cloud database CRUD, cloud functions, storage, and datacom components with permission setup.
Files
When to use this skill
Use this skill whenever the user wants to:
- Use uniCloud cloud development services
- Work with cloud databases (add, query, update, delete data)
- Create and deploy cloud functions
- Use cloud storage for file uploads and management
- Implement datacom components for data binding
- Integrate backend services with uni-app
- Set up uniCloud project and configuration
- Handle cloud database permissions and security
How to use this skill
This skill is organized to match the official uniCloud documentation:
1. Start with setup and project configuration:
examples/guide/intro.mdexamples/guide/project-setup.mdexamples/guide/cloud-space.md
2. Choose the cloud capability:
- Database →
examples/database/ - Cloud functions →
examples/functions/ - Storage →
examples/storage/ - Datacom →
examples/datacom/ - Security/permission →
examples/security/
3. Open the API reference:
api/cloud-api.md
Important Notes:
- This skill focuses on uniCloud integration and usage, not general backend frameworks
- Each example includes official documentation URL
- Follow official permission and security guidance for production
Examples and Templates
Examples
Located in examples/:
- guide/ - Intro, project setup, cloud space creation
- database/ - CRUD, query, index, permissions
- functions/ - Function structure, deploy, call
- storage/ - Upload, download, delete
- datacom/ - datacom components and binding
- security/ - permissions and security rules
Best Practices
1. Security: Always set proper database permissions and rules 2. Performance: Use indexes for frequently queried fields 3. Cost: Optimize cloud function execution time 4. Error handling: Implement proper error handling for all cloud operations 5. Data validation: Validate data before saving to database
Resources
- Official Documentation: https://doc.dcloud.net.cn/uniCloud/
- Cloud Database: https://doc.dcloud.net.cn/uniCloud/database.html
- Cloud Functions: https://doc.dcloud.net.cn/uniCloud/cf-functions.html
- Cloud Storage: https://doc.dcloud.net.cn/uniCloud/storage.html
Keywords
unicloud, uniCloud, cloud development, cloud database, cloud functions, cloud storage, datacom, 云开发, 云数据库, 云函数, 云存储
能力边界
✅ 适用场景
- 当你需要使用此技能对应的技术栈时
- 当项目需要遵循最佳实践时
- 当需要快速上手或深入理解核心概念时
⚠️ 需要注意
- 复杂业务逻辑需要结合具体场景调整
- 性能优化需要根据实际数据量评估
❌ 不适用场景
- 不相关的技术栈或框架
- 需要完全自定义的特殊场景
常见陷阱 (Gotchas)
1. 版本兼容性:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异 2. 配置文件格式:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查 3. 环境变量:确保所有必要的环境变量已正确设置,敏感信息不要硬编码 4. 依赖冲突:多版本共存时注意依赖冲突,使用 lock 文件锁定版本 5. 性能陷阱:大数据量场景下注意性能优化,避免 N+1 查询等常见问题
使用流程
Step 1: 环境准备
确保开发环境已安装必要的依赖和工具。
Step 2: 配置初始化
根据项目需求进行基础配置。
Step 3: 核心功能使用
按照示例代码实现核心功能。
Step 4: 测试验证
运行测试确保功能正常。
Step 5: 部署上线
完成开发后进行部署和监控。
uniCloud API 参考
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
云数据库 API
获取数据库引用
const db = uniCloud.database()获取集合引用
const collection = db.collection('users')查询数据
// 获取所有数据
collection.get().then(res => {
console.log(res.data)
})
// 条件查询
collection.where({
age: db.command.gt(18)
}).get().then(res => {
console.log(res.data)
})
// 分页查询
collection.skip(0).limit(10).get().then(res => {
console.log(res.data)
})添加数据
collection.add({
name: 'John',
age: 25
}).then(res => {
console.log(res.id)
})更新数据
collection.doc('doc-id').update({
age: 26
}).then(res => {
console.log('更新成功')
})删除数据
collection.doc('doc-id').remove().then(res => {
console.log('删除成功')
})云函数 API
调用云函数
uniCloud.callFunction({
name: 'function-name',
data: {
param1: 'value1'
}
}).then(res => {
console.log(res.result)
})云存储 API
上传文件
uniCloud.uploadFile({
filePath: 'path/to/file',
cloudPath: 'cloud/path/file.jpg'
}).then(res => {
console.log(res.fileID)
})下载文件
uniCloud.downloadFile({
fileID: 'cloud://xxx.jpg'
}).then(res => {
console.log(res.tempFilePath)
})删除文件
uniCloud.deleteFile({
fileList: ['cloud://xxx.jpg']
}).then(res => {
console.log('删除成功')
})参考资源
- uniCloud API 文档:https://doc.dcloud.net.cn/uniCloud/client-sdk.html
云数据库 CRUD
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
新增数据
const db = uniCloud.database()
const users = db.collection('users')
users.add({
name: 'Alice',
age: 20
}).then(res => {
console.log('新增 ID', res.id)
})查询数据
users.get().then(res => {
console.log(res.data)
})更新数据
users.doc('doc-id').update({
age: 21
})删除数据
users.doc('doc-id').remove()参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html
云数据库索引
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
使用场景
- 提升高频查询性能
- 支持复合索引提升多条件查询效率
示例
- 在 uniCloud 控制台为集合创建索引
- 为常用的查询字段(如 userId、createdAt)建立索引
参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html
云数据库权限控制
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
说明
- 通过数据库权限规则限制读写
- 配合用户身份(如用户登录态)实现访问控制
示例(规则示意)
{
"read": true,
"write": "auth.uid == _id"
}参考资源
- https://doc.dcloud.net.cn/uniCloud/
云数据库查询
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
条件查询
const db = uniCloud.database()
const users = db.collection('users')
users.where({
age: db.command.gt(18)
}).get().then(res => {
console.log(res.data)
})排序与分页
users.orderBy('createdAt', 'desc')
.skip(0)
.limit(10)
.get()字段筛选
users.field({
name: true,
age: true
}).get()参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html
datacom 组件与数据绑定
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
使用场景
- 快速绑定云数据库数据
- 通过组件实现低代码数据展示
说明
在 uniCloud 体系中,datacom 组件用于快速构建数据列表、详情页等场景。使用时需关注组件配置、数据源与权限规则。
参考资源
- https://doc.dcloud.net.cn/uniCloud/
云函数调用
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/cf-functions.html
前端调用示例
uniCloud.callFunction({
name: 'getUser',
data: { userId: '123' }
}).then(res => {
console.log(res.result)
})参考资源
- https://doc.dcloud.net.cn/uniCloud/cf-functions.html
云函数创建
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/cf-functions.html
创建云函数
1. 在项目根目录创建 cloudfunctions/。 2. 新建函数目录(如 getUser)。 3. 编写 index.js 入口。
'use strict'
exports.main = async (event, context) => {
return {
code: 0,
data: 'Hello uniCloud'
}
}参考资源
- https://doc.dcloud.net.cn/uniCloud/cf-functions.html
云服务空间创建与关联
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
创建服务空间
1. 登录 DCloud 开发者中心。 2. 进入 uniCloud 控制台。 3. 新建服务空间(选择阿里云或腾讯云)。
关联服务空间
在 HBuilderX 中:
1. 右键项目 → uniCloud → 关联云服务空间。 2. 选择服务空间与云服务商。 3. 关联完成后即可使用云数据库、云函数、云存储。
注意事项
- 不同云服务商的配额、费用与功能存在差异。
- 建议为不同环境(开发/测试/生产)创建独立空间。
参考资源
- https://doc.dcloud.net.cn/uniCloud/
uniCloud 云开发指南
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
什么是 uniCloud
uniCloud 是 DCloud 联合阿里云、腾讯云,为 uni-app 开发者提供的基于 serverless 模式和 js 编程的云开发平台。
核心功能
1. 云数据库
- 无需自建数据库
- 自动扩容
- 支持 JSON 文档存储
- 支持关系型数据
2. 云函数
- 无需管理服务器
- 按量计费
- 支持 Node.js
- 自动扩缩容
3. 云存储
- 文件上传下载
- CDN 加速
- 图片处理
- 安全防护
4. 前端网页托管
- 静态网站托管
- CDN 加速
- 自定义域名
服务空间
创建服务空间
1. 登录 DCloud 开发者中心 2. 进入 uniCloud 控制台 3. 创建服务空间 4. 选择云服务商(阿里云/腾讯云)
关联服务空间
在 HBuilderX 中: 1. 右键项目 → uniCloud → 关联云服务空间 2. 选择服务空间 3. 选择云服务商
项目结构
my-uniapp-project/
├── cloudfunctions/ # 云函数目录
│ ├── function1/
│ │ ├── index.js
│ │ └── package.json
│ └── ...
├── uniCloud/
│ └── database/ # 数据库 schema
│ └── db_init.json
└── ...快速开始
1. 创建服务空间
在 DCloud 开发者中心创建服务空间。
2. 关联服务空间
在 HBuilderX 中关联服务空间。
3. 初始化云数据库
// 在 uniCloud 控制台创建数据表
// 或使用 db_init.json 初始化4. 使用云数据库
// 在页面中使用
const db = uniCloud.database()
const collection = db.collection('users')
collection.get().then(res => {
console.log(res.data)
})参考资源
- uniCloud 文档:https://doc.dcloud.net.cn/uniCloud/
- 云数据库:https://doc.dcloud.net.cn/uniCloud/database.html
- 云函数:https://doc.dcloud.net.cn/uniCloud/cf-functions.html
uniCloud 项目初始化
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
使用场景
- 创建新 uni-app 项目并启用 uniCloud
- 为已有项目关联云服务空间
- 初始化云函数与数据库目录
步骤
1. 创建或打开项目(HBuilderX 或 CLI 项目均可)。 2. 启用 uniCloud:
- 在 HBuilderX 中右键项目 →
uniCloud→关联云服务空间。
3. 确认目录结构:
my-uniapp-project/
├── cloudfunctions/ # 云函数目录
├── uniCloud/ # 云数据库与存储配置
└── ...4. 初始化云数据库:
- 使用
uniCloud/database下的 schema 或控制台创建集合。
示例
// 获取数据库引用
const db = uniCloud.database()
const collection = db.collection('users')参考资源
- https://doc.dcloud.net.cn/uniCloud/
权限与安全规则
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
关键点
- 按最小权限原则配置读写规则
- 对敏感数据进行字段级控制
- 使用用户身份信息限制访问范围
示例(规则示意)
{
"read": "auth.uid != null",
"write": "auth.uid == _id"
}参考资源
- https://doc.dcloud.net.cn/uniCloud/
云存储删除
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/storage.html
删除文件
uniCloud.deleteFile({
fileList: ['cloud://xxx/xxx.png']
})参考资源
- https://doc.dcloud.net.cn/uniCloud/storage.html
云存储下载
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/storage.html
获取临时链接
uniCloud.getTempFileURL({
fileList: ['cloud://xxx/xxx.png']
}).then(res => {
console.log(res.fileList)
})参考资源
- https://doc.dcloud.net.cn/uniCloud/storage.html
云存储上传
官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/storage.html
上传文件
uniCloud.uploadFile({
filePath: '/static/logo.png',
cloudPath: 'images/logo.png'
}).then(res => {
console.log('fileID:', res.fileID)
})参考资源
- https://doc.dcloud.net.cn/uniCloud/storage.html
MIT License
Copyright (c) 2024 partme-ai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.