TudadaStore API
TudadaStore API (云存储)
与设备无关地将用户数据保存/查询到云端。
容量限制: value 最大 2KB
getTudadaStore()
返回 TudadaStore 单例实例。
返回值:
| 字段 | 类型 | 说明 |
|---|---|---|
| (返回值) | TudadaStore | 云存储实例 |
实例方法:
| 成员 | 类型 | 说明 |
|---|---|---|
get(options) | void | 从云端查询数据 |
save(options) | void | 将数据保存到云端 |
store.get(options) 选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | string | ✅ | 查询键 |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
store.get 成功响应:
| 字段 | 类型 | 说明 |
|---|---|---|
value | string | null | 存储的值(不存在时为 null) |
store.save(options) 选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | string | ✅ | 存储键 |
value | string | ✅ | 存储值(最大 2KB) |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
const store = TudadaSDK.getTudadaStore();
// 保存值(最大 2KB)
store.save({
key: 'userScore',
value: '1000',
success: () => console.log('云端保存完成'),
fail: (err) => console.error('保存失败:', err.errMsg),
});
// 查询值
store.get({
key: 'userScore',
success: (res) => {
if (res.value !== null) {
console.log('分数:', res.value);
} else {
console.log('没有已保存的值');
}
},
});
tudadaStoreGet(options) / tudadaStoreSave(options)
直接调用 TudadaStore 的方式。
tudadaStoreSave(options) 选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | string | ✅ | 存储键 |
value | string | ✅ | 存储值(最大 2KB) |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
tudadaStoreGet(options) 选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | string | ✅ | 查询键 |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
tudadaStoreGet 成功响应:
| 字段 | 类型 | 说明 |
|---|---|---|
value | string | null | 存储的值(不存在时为 null) |
// 保存
TudadaSDK.tudadaStoreSave({
key: 'gameState',
value: JSON.stringify({ level: 5, coins: 300 }),
success: () => console.log('保存完成'),
fail: (err) => console.error('保存失败:', err.errMsg),
});
// 查询
TudadaSDK.tudadaStoreGet({
key: 'gameState',
success: (res) => {
if (res.value) {
const state = JSON.parse(res.value);
console.log('等级:', state.level);
}
},
});