storage.get
描述
获取存储的数据
使用示例
import { SmartStorageAbility } from '@ray-js/panel-sdk';
const storage = new SmartStorageAbility();
storage.init();
const getLocalData: TReturnRes = (_res) => {
console.log(_res);
};
storage.get('mockKey', getLocalData).then((res: TReturnRes) => {
const { __isEqual__ } = res || {};
if (__isEqual__) {
// 判读云端返回的数据是否与本地数据一致,如果一致 __isEqual__ = true, 可用来优化更新频率
}
console.log(res);
});
storage.set
描述
添加存储数据
使用示例
import { SmartStorageAbility } from '@ray-js/panel-sdk';
const storage = new SmartStorageAbility();
storage.init();
// 存储
// 注意⚠️:由于接口保存长度限制🚫,value 的值字符串长度(内部会转为字符串)建议在256, 最大不超过1024,超过1024会保存失败
const value = { a: 1, b: [1,2,3] };
storage.set('mockKey', value).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
storage.remove
描述
删除存储的数据
使用示例
import { SmartStorageAbility } from '@ray-js/panel-sdk';
const storage = new SmartStorageAbility();
storage.init();
// 删除
storage.remove('mockKey').then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。