# Api域:
const storage = kreator.storage:
# storage.getStorage(options: StorageRequestInterface)
异步获取指定key的storage缓存值。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| options | StorageRequestInterface | 是 | 异步入参对象 |
# StorageRequestInterface类型:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | storage中指定的key | |
| callback | function | 否 | get完成回调 |
# 返回值
any storage中key对应的data
key对应的缓存内容
storage.getStorage({
key: 'kreator-test-storage'
}).then(res=>{
const testStorage = res;
alert(`storage字段kreator-test-storage值为${testStorage}`);
});
# storage.getStorageSync(key: string)
同步获取指定key的storage缓存值。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | / | 是 | storage中指定的key |
# 返回值
any data
key对应的缓存内容
const testStorage = storage.getStorageSync('kreator-test-storage');
# storage.removeStorage(options: StorageRequestInterface)
异步删除指定key的storage值。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| options | StorageRequestInterface | 是 | 异步入参对象 |
# StorageRequestInterface类型:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | storage中指定的key | |
| callback | function | 否 | remove完成回调 |
# 返回值
无
storage.removeStorage({
key:'kreator-test-storage'
}).then(res=>{
alert('storage字段kreator-test-storage已删除');
});
# storage.removeStorageSync(key: string)
同步删除指定key的storage值。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | storage中指定的key |
# 返回值
无
storage.removeStorageSync('kreator-test-storage');
# storage.setStorage(options: StorageRequestInterface)
异步新增一个新的storage字段。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| options | StorageRequestInterface | 是 | 异步入参对象 |
# StorageRequestInterface类型:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | storage中指定的key | |
| value | string | 是 | storage中key对应的值 | |
| callback | function | 否 | set完成回调 |
# 返回值
无
kreator.storage.setStorage({
key:'kreator-test-storage',
value: 'test~'
}).then(res=>{
alert('storage字段kreator-test-storage已植入,值为test~');
});
# storage.setStorageSync(key: string,value: any)
同步新增一个新的storage字段。
# 参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | storage中指定的key | |
| value | string | 是 | storage中key对应的值 |
# 返回值
无
kreator.storage.setStorageSync('kreator-test-storage','test~')