wsz987

兴趣使然 & 见证成长

0%

unicloud-db 踩坑

uniCloud 控制端
<unicloud-db> 官方文档

1
2
3
4
5
6
7
<unicloud-db v-slot:default="{data, loading, error, options}" collection="table1"  ref="udb">
<view v-if="error">{{error.message}}</view>
<view v-else-if="loading">正在加载...</view>
<view v-else>
{{ data}}
</view>
</unicloud-db>

使用前需配置 DB Schema 官方文档

[^permission]: 必须开启相关权限才是使用组件 如基本使用的read
[^properties]: 字段校验 用于后期数据添加或修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"name": {
"bsonType": "string"
},
"tags": {
"bsonType": "array"
},
"downloadURL": {
"bsonType": "string"
}
}
}

properties 配置后才能 add 添加数据

1
this.$refs.udb.add(value)
1
2
3
4
5
6
7
8
9
10
11
this.$refs.udb.add(value, {
toastTitle: '新增成功', // toast提示语
success: (res) => { // 新增成功后的回调
const { code, message } = res
},
fail: (err) => { // 新增失败后的回调
const { message } = err
},
complete: () => { // 完成后的回调
}
})