Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
a2b293c2
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a2b293c2
编写于
3月 19, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
!2142 ohos Handling API interface integrity and consistency
Merge pull request !2142 from PaDaBoo/master
上级
81f14f31
d2b7934f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
140 addition
and
81 deletion
+140
-81
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
...pplication-dev/reference/apis/js-apis-data-preferences.md
+25
-23
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
+115
-58
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
浏览文件 @
a2b293c2
...
@@ -15,10 +15,12 @@ import data_Preferences from '@ohos.data.preferences'
...
@@ -15,10 +15,12 @@ import data_Preferences from '@ohos.data.preferences'
## 属性
## 属性
**系统能力**
:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。
<br>
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
|
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。
<br>
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
|
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
## data_Preferences.getPreferences
## data_Preferences.getPreferences
...
@@ -77,8 +79,8 @@ getPreferences(context: Context, name: string): Promise<Preferences>
...
@@ -77,8 +79,8 @@ getPreferences(context: Context, name: string): Promise<Preferences>
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences'
import data_Preferences from '@ohos.data.preferences'
var path = this.context.getDataBaseDir()
var path = this.context.getDataBaseDir()
let promise = data_Preferences.getPreferences(this.context, 'mystore')
let promise
Pre
= data_Preferences.getPreferences(this.context, 'mystore')
promise.then((preferences) => {
promise
Pre
.then((preferences) => {
preferences.putSync('startup', 'auto')
preferences.putSync('startup', 'auto')
preferences.flushSync()
preferences.flushSync()
}).catch((err) => {
}).catch((err) => {
...
@@ -89,7 +91,7 @@ getPreferences(context: Context, name: string): Promise<Preferences>
...
@@ -89,7 +91,7 @@ getPreferences(context: Context, name: string): Promise<Preferences>
## data_Preferences.deletePreferences
## data_Preferences.deletePreferences
deletePreferences(context: Context, name: string, callback: AsyncCallback
<
void
>
)
deletePreferences(context: Context, name: string, callback: AsyncCallback
<
void
>
)
: void
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
...
@@ -139,8 +141,8 @@ deletePreferences(context: Context, name: string): Promise<void>
...
@@ -139,8 +141,8 @@ deletePreferences(context: Context, name: string): Promise<void>
```
```
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences'
import data_Preferences from '@ohos.data.preferences'
let promise = data_Preferences.deletePreferences(this.context, 'mystore')
let promise
delPre
= data_Preferences.deletePreferences(this.context, 'mystore')
promise.then(() => {
promise
delPre
.then(() => {
console.info("Deleted successfully.")
console.info("Deleted successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Deleted failed with err: " + err)
console.info("Deleted failed with err: " + err)
...
@@ -150,7 +152,7 @@ deletePreferences(context: Context, name: string): Promise<void>
...
@@ -150,7 +152,7 @@ deletePreferences(context: Context, name: string): Promise<void>
## data_Preferences.removePreferencesFromCache
## data_Preferences.removePreferencesFromCache
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback
<
Preferences
>
): void
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback
<
void
>
): void
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
...
@@ -163,7 +165,7 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
...
@@ -163,7 +165,7 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| context | Context | 是 | 应用程序或功能的上下文 |
| context | Context | 是 | 应用程序或功能的上下文 |
| name | string | 是 | 应用程序内部数据存储名称。 |
| name | string | 是 | 应用程序内部数据存储名称。 |
| callback | AsyncCallback
<
[Preferences](#preferences)
>
| 是 | 回调函数。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
-
示例:
-
示例:
```
```
...
@@ -204,8 +206,8 @@ removePreferencesFromCache(context: Context, name: string): Promise<void>
...
@@ -204,8 +206,8 @@ removePreferencesFromCache(context: Context, name: string): Promise<void>
```
```
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences'
import data_Preferences from '@ohos.data.preferences'
let promise = data_Preferences.removePreferencesFromCache(this.context, 'mystore')
let promise
revPre
= data_Preferences.removePreferencesFromCache(this.context, 'mystore')
promise.then(() => {
promise
revPre
.then(() => {
console.info("Removed preferences from cache successfully.")
console.info("Removed preferences from cache successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Removed preferences from cache failed with err: " + err)
console.info("Removed preferences from cache failed with err: " + err)
...
@@ -270,8 +272,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
...
@@ -270,8 +272,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
-
示例:
-
示例:
```
```
let promise = preferences.get('startup', 'default')
let promise
get
= preferences.get('startup', 'default')
promise.then((value) => {
promise
get
.then((value) => {
console.info("The value of startup is " + value)
console.info("The value of startup is " + value)
}).catch((err) => {
}).catch((err) => {
console.info("Get the value of startup failed with err: " + err)
console.info("Get the value of startup failed with err: " + err)
...
@@ -331,8 +333,8 @@ put(key: string, value: ValueType): Promise<void>
...
@@ -331,8 +333,8 @@ put(key: string, value: ValueType): Promise<void>
-
示例:
-
示例:
```
```
let promise = preferences.put('startup', 'auto')
let promise
put
= preferences.put('startup', 'auto')
promise.then(() => {
promise
put
.then(() => {
console.info("Put the value of startup successfully.")
console.info("Put the value of startup successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Put the value of startup failed with err: " + err)
console.info("Put the value of startup failed with err: " + err)
...
@@ -397,8 +399,8 @@ has(key: string): Promise<boolean>
...
@@ -397,8 +399,8 @@ has(key: string): Promise<boolean>
-
示例:
-
示例:
```
```
let promise = preferences.has('startup')
let promise
has
= preferences.has('startup')
promise.then((isExist) => {
promise
has
.then((isExist) => {
if (isExist) {
if (isExist) {
console.info("The key of startup is contained.")
console.info("The key of startup is contained.")
}
}
...
@@ -458,8 +460,8 @@ delete(key: string): Promise<void>
...
@@ -458,8 +460,8 @@ delete(key: string): Promise<void>
-
示例:
-
示例:
```
```
let promise = preferences.delete('startup')
let promise
del
= preferences.delete('startup')
promise.then(() => {
promise
del
.then(() => {
console.info("Deleted startup key successfully.")
console.info("Deleted startup key successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Delete startup key failed with err: " + err)
console.info("Delete startup key failed with err: " + err)
...
@@ -511,8 +513,8 @@ flush(): Promise<void>
...
@@ -511,8 +513,8 @@ flush(): Promise<void>
-
示例:
-
示例:
```
```
let promise = preferences.flush()
let promise
flush
= preferences.flush()
promise.then(() => {
promise
flush
.then(() => {
console.info("Flushed to file successfully.")
console.info("Flushed to file successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Flush to file failed with err: " + err)
console.info("Flush to file failed with err: " + err)
...
@@ -564,8 +566,8 @@ clear(): Promise<void>
...
@@ -564,8 +566,8 @@ clear(): Promise<void>
-
示例:
-
示例:
```
```
let promise = preferences.clear()
let promise
clear
= preferences.clear()
promise.then(() => {
promise
clear
.then(() => {
console.info("Cleared to file successfully.")
console.info("Cleared to file successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Clear to file failed with err: " + err)
console.info("Clear to file failed with err: " + err)
...
...
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
浏览文件 @
a2b293c2
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
>  **说明:**
>  **说明:**
> 从API Version 9开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
>
本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。<br/>
从API Version 9开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
## 导入模块
## 导入模块
...
@@ -13,25 +13,24 @@
...
@@ -13,25 +13,24 @@
import dataStorage from '@ohos.data.storage'
import dataStorage from '@ohos.data.storage'
```
```
## 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
## 属性
## 属性
**系统能力**
:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
## dataStorage.getStorageSync
<sup>(deprecated) </sup>
## dataStorage.getStorageSync
getStorageSync(path: string): Storage
getStorageSync(path: string): Storage
读取指定文件,将数据加载到Storage实例,用于数据操作,此方法为同步方法。
读取指定文件,将数据加载到Storage实例,用于数据操作,此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -55,12 +54,14 @@ getStorageSync(path: string): Storage
...
@@ -55,12 +54,14 @@ getStorageSync(path: string): Storage
```
```
## dataStorage.getStorage
<sup>(deprecated) </sup>
## dataStorage.getStorage
getStorage(path: string, callback: AsyncCallback
<
Storage
>
): void
getStorage(path: string, callback: AsyncCallback
<
Storage
>
): void
读取指定文件,将数据加载到Storage实例,用于数据操作,使用callback形式返回结果。
读取指定文件,将数据加载到Storage实例,用于数据操作,使用callback形式返回结果。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -85,12 +86,14 @@ getStorage(path: string, callback: AsyncCallback<Storage>): void
...
@@ -85,12 +86,14 @@ getStorage(path: string, callback: AsyncCallback<Storage>): void
```
```
## dataStorage.getStorage
<sup>(deprecated) </sup>
## dataStorage.getStorage
getStorage(path: string): Promise
<
Storage
>
getStorage(path: string): Promise
<
Storage
>
读取指定文件,将数据加载到Storage实例,用于数据操作,使用Promise方式作为异步方法。
读取指定文件,将数据加载到Storage实例,用于数据操作,使用Promise方式作为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -108,8 +111,8 @@ getStorage(path: string): Promise<Storage>
...
@@ -108,8 +111,8 @@ getStorage(path: string): Promise<Storage>
var context = featureAbility.getContext()
var context = featureAbility.getContext()
var path = await context.getFilesDir()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
let promise
getSt
= dataStorage.getStorage(path + '/mystore')
promise.then((storage) => {
promise
getSt
.then((storage) => {
storage.putSync('startup', 'auto')
storage.putSync('startup', 'auto')
storage.flushSync()
storage.flushSync()
}).catch((err) => {
}).catch((err) => {
...
@@ -118,12 +121,14 @@ getStorage(path: string): Promise<Storage>
...
@@ -118,12 +121,14 @@ getStorage(path: string): Promise<Storage>
```
```
## dataStorage.deleteStorageSync
<sup>(deprecated) </sup>
## dataStorage.deleteStorageSync
deleteStorageSync(path: string): void
deleteStorageSync(path: string): void
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,此方法为同步方法。
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -135,12 +140,14 @@ deleteStorageSync(path: string): void
...
@@ -135,12 +140,14 @@ deleteStorageSync(path: string): void
```
```
## dataStorage.deleteStorage
<sup>(deprecated) </sup>
## dataStorage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback
<
void
>
)
deleteStorage(path: string, callback: AsyncCallback
<
void
>
)
: void
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -159,12 +166,14 @@ deleteStorage(path: string, callback: AsyncCallback<void>)
...
@@ -159,12 +166,14 @@ deleteStorage(path: string, callback: AsyncCallback<void>)
```
```
## dataStorage.deleteStorage
<sup>(deprecated) </sup>
## dataStorage.deleteStorage
deleteStorage(path: string): Promise
<
void
>
deleteStorage(path: string): Promise
<
void
>
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -177,8 +186,8 @@ deleteStorage(path: string): Promise<void>
...
@@ -177,8 +186,8 @@ deleteStorage(path: string): Promise<void>
-
示例:
-
示例:
```
```
let promise = dataStorage.deleteStorage(path + '/mystore')
let promise
delSt
= dataStorage.deleteStorage(path + '/mystore')
promise.then(() => {
promise
delSt
.then(() => {
console.info("Deleted successfully.")
console.info("Deleted successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Deleted failed with err: " + err)
console.info("Deleted failed with err: " + err)
...
@@ -186,7 +195,7 @@ deleteStorage(path: string): Promise<void>
...
@@ -186,7 +195,7 @@ deleteStorage(path: string): Promise<void>
```
```
## dataStorage.removeStorageFromCacheSync
<sup>(deprecated) </sup>
## dataStorage.removeStorageFromCacheSync
removeStorageFromCacheSync(path: string): void
removeStorageFromCacheSync(path: string): void
...
@@ -194,6 +203,8 @@ removeStorageFromCacheSync(path: string): void
...
@@ -194,6 +203,8 @@ removeStorageFromCacheSync(path: string): void
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -205,19 +216,21 @@ removeStorageFromCacheSync(path: string): void
...
@@ -205,19 +216,21 @@ removeStorageFromCacheSync(path: string): void
```
```
## dataStorage.removeStorageFromCache
<sup>(deprecated) </sup>
## dataStorage.removeStorageFromCache
removeStorageFromCache(path: string, callback: AsyncCallback
<
Storage
>
): void
removeStorageFromCache(path: string, callback: AsyncCallback
<
void
>
): void
从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| path | string | 是 | 应用程序内部数据存储路径。 |
| path | string | 是 | 应用程序内部数据存储路径。 |
| callback | AsyncCallback
<
[Storage](#storage)
>
| 是 | 回调函数。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
-
示例:
-
示例:
```
```
...
@@ -231,7 +244,7 @@ removeStorageFromCache(path: string, callback: AsyncCallback<Storage>): vo
...
@@ -231,7 +244,7 @@ removeStorageFromCache(path: string, callback: AsyncCallback<Storage>): vo
```
```
## dataStorage.removeStorageFromCache
<sup>(deprecated) </sup>
## dataStorage.removeStorageFromCache
removeStorageFromCache(path: string): Promise
<
void
>
removeStorageFromCache(path: string): Promise
<
void
>
...
@@ -239,6 +252,8 @@ removeStorageFromCache(path: string): Promise<void>
...
@@ -239,6 +252,8 @@ removeStorageFromCache(path: string): Promise<void>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -251,8 +266,8 @@ removeStorageFromCache(path: string): Promise<void>
...
@@ -251,8 +266,8 @@ removeStorageFromCache(path: string): Promise<void>
-
示例:
-
示例:
```
```
let promise = dataStorage.removeStorageFromCache(path + '/mystore')
let promise
revSt
= dataStorage.removeStorageFromCache(path + '/mystore')
promise.then(() => {
promise
revSt
.then(() => {
console.info("Removed storage from cache successfully.")
console.info("Removed storage from cache successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Removed storage from cache failed with err: " + err)
console.info("Removed storage from cache failed with err: " + err)
...
@@ -260,12 +275,12 @@ removeStorageFromCache(path: string): Promise<void>
...
@@ -260,12 +275,12 @@ removeStorageFromCache(path: string): Promise<void>
```
```
## Storage
<sup>(deprecated) </sup>
## Storage
提供获取和修改存储数据的接口。
提供获取和修改存储数据的接口。
### getSync
<sup>(deprecated) </sup>
### getSync
getSync(key: string, defValue: ValueType): ValueType
getSync(key: string, defValue: ValueType): ValueType
...
@@ -273,6 +288,8 @@ getSync(key: string, defValue: ValueType): ValueType
...
@@ -273,6 +288,8 @@ getSync(key: string, defValue: ValueType): ValueType
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -291,7 +308,7 @@ getSync(key: string, defValue: ValueType): ValueType
...
@@ -291,7 +308,7 @@ getSync(key: string, defValue: ValueType): ValueType
```
```
### get
<sup>(deprecated) </sup>
### get
get(key: string, defValue: ValueType, callback: AsyncCallback
<
ValueType
>
): void
get(key: string, defValue: ValueType, callback: AsyncCallback
<
ValueType
>
): void
...
@@ -299,6 +316,8 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>):
...
@@ -299,6 +316,8 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>):
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -318,7 +337,7 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>):
...
@@ -318,7 +337,7 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>):
```
```
### get
<sup>(deprecated) </sup>
### get
get(key: string, defValue: ValueType): Promise
<
ValueType
>
get(key: string, defValue: ValueType): Promise
<
ValueType
>
...
@@ -326,6 +345,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
...
@@ -326,6 +345,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
**参数:**
-
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -339,8 +360,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
...
@@ -339,8 +360,8 @@ get(key: string, defValue: ValueType): Promise<ValueType>
-
示例:
-
示例:
```
```
let promise = storage.get('startup', 'default')
let promise
get
= storage.get('startup', 'default')
promise.then((value) => {
promise
get
.then((value) => {
console.info("The value of startup is " + value)
console.info("The value of startup is " + value)
}).catch((err) => {
}).catch((err) => {
console.info("Get the value of startup failed with err: " + err)
console.info("Get the value of startup failed with err: " + err)
...
@@ -348,7 +369,7 @@ get(key: string, defValue: ValueType): Promise<ValueType>
...
@@ -348,7 +369,7 @@ get(key: string, defValue: ValueType): Promise<ValueType>
```
```
### putSync
<sup>(deprecated) </sup>
### putSync
putSync(key: string, value: ValueType): void
putSync(key: string, value: ValueType): void
...
@@ -356,6 +377,8 @@ putSync(key: string, value: ValueType): void
...
@@ -356,6 +377,8 @@ putSync(key: string, value: ValueType): void
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -368,7 +391,7 @@ putSync(key: string, value: ValueType): void
...
@@ -368,7 +391,7 @@ putSync(key: string, value: ValueType): void
```
```
### put
<sup>(deprecated) </sup>
### put
put(key: string, value: ValueType, callback: AsyncCallback
<
void
>
): void
put(key: string, value: ValueType, callback: AsyncCallback
<
void
>
): void
...
@@ -376,6 +399,8 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void
...
@@ -376,6 +399,8 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -395,7 +420,7 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void
...
@@ -395,7 +420,7 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void
```
```
### put
<sup>(deprecated) </sup>
### put
put(key: string, value: ValueType): Promise
<
void
>
put(key: string, value: ValueType): Promise
<
void
>
...
@@ -403,6 +428,8 @@ put(key: string, value: ValueType): Promise<void>
...
@@ -403,6 +428,8 @@ put(key: string, value: ValueType): Promise<void>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -416,8 +443,8 @@ put(key: string, value: ValueType): Promise<void>
...
@@ -416,8 +443,8 @@ put(key: string, value: ValueType): Promise<void>
-
示例:
-
示例:
```
```
let promise = storage.put('startup', 'auto')
let promise
put
= storage.put('startup', 'auto')
promise.then(() => {
promise
put
.then(() => {
console.info("Put the value of startup successfully.")
console.info("Put the value of startup successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Put the value of startup failed with err: " + err)
console.info("Put the value of startup failed with err: " + err)
...
@@ -425,7 +452,7 @@ put(key: string, value: ValueType): Promise<void>
...
@@ -425,7 +452,7 @@ put(key: string, value: ValueType): Promise<void>
```
```
### hasSync
<sup>(deprecated) </sup>
### hasSync
hasSync(key: string): boolean
hasSync(key: string): boolean
...
@@ -433,6 +460,8 @@ hasSync(key: string): boolean
...
@@ -433,6 +460,8 @@ hasSync(key: string): boolean
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -452,7 +481,7 @@ hasSync(key: string): boolean
...
@@ -452,7 +481,7 @@ hasSync(key: string): boolean
```
```
### has
<sup>(deprecated) </sup>
### has
has(key: string, callback: AsyncCallback
<
boolean
>
): boolean
has(key: string, callback: AsyncCallback
<
boolean
>
): boolean
...
@@ -460,6 +489,8 @@ has(key: string, callback: AsyncCallback<boolean>): boolean
...
@@ -460,6 +489,8 @@ has(key: string, callback: AsyncCallback<boolean>): boolean
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -485,7 +516,7 @@ has(key: string, callback: AsyncCallback<boolean>): boolean
...
@@ -485,7 +516,7 @@ has(key: string, callback: AsyncCallback<boolean>): boolean
```
```
### has
<sup>(deprecated) </sup>
### has
has(key: string): Promise
<
boolean
>
has(key: string): Promise
<
boolean
>
...
@@ -493,6 +524,8 @@ has(key: string): Promise<boolean>
...
@@ -493,6 +524,8 @@ has(key: string): Promise<boolean>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -505,8 +538,8 @@ has(key: string): Promise<boolean>
...
@@ -505,8 +538,8 @@ has(key: string): Promise<boolean>
-
示例:
-
示例:
```
```
let promise = storage.has('startup')
let promise
has
= storage.has('startup')
promise.then((isExist) => {
promise
has
.then((isExist) => {
if (isExist) {
if (isExist) {
console.info("The key of startup is contained.")
console.info("The key of startup is contained.")
}
}
...
@@ -516,7 +549,7 @@ has(key: string): Promise<boolean>
...
@@ -516,7 +549,7 @@ has(key: string): Promise<boolean>
```
```
### deleteSync
<sup>(deprecated) </sup>
### deleteSync
deleteSync(key: string): void
deleteSync(key: string): void
...
@@ -524,6 +557,8 @@ deleteSync(key: string): void
...
@@ -524,6 +557,8 @@ deleteSync(key: string): void
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -535,7 +570,7 @@ deleteSync(key: string): void
...
@@ -535,7 +570,7 @@ deleteSync(key: string): void
```
```
### delete
<sup>(deprecated) </sup>
### delete
delete(key: string, callback: AsyncCallback
<
void
>
): void
delete(key: string, callback: AsyncCallback
<
void
>
): void
...
@@ -543,6 +578,8 @@ delete(key: string, callback: AsyncCallback<void>): void
...
@@ -543,6 +578,8 @@ delete(key: string, callback: AsyncCallback<void>): void
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -561,7 +598,7 @@ delete(key: string, callback: AsyncCallback<void>): void
...
@@ -561,7 +598,7 @@ delete(key: string, callback: AsyncCallback<void>): void
```
```
### delete
<sup>(deprecated) </sup>
### delete
delete(key: string): Promise
<
void
>
delete(key: string): Promise
<
void
>
...
@@ -569,6 +606,8 @@ delete(key: string): Promise<void>
...
@@ -569,6 +606,8 @@ delete(key: string): Promise<void>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -581,8 +620,8 @@ delete(key: string): Promise<void>
...
@@ -581,8 +620,8 @@ delete(key: string): Promise<void>
-
示例:
-
示例:
```
```
let promise = storage.delete('startup')
let promise
del
= storage.delete('startup')
promise.then(() => {
promise
del
.then(() => {
console.info("Deleted startup key successfully.")
console.info("Deleted startup key successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Delete startup key failed with err: " + err)
console.info("Delete startup key failed with err: " + err)
...
@@ -590,7 +629,7 @@ delete(key: string): Promise<void>
...
@@ -590,7 +629,7 @@ delete(key: string): Promise<void>
```
```
### flushSync
<sup>(deprecated) </sup>
### flushSync
flushSync(): void
flushSync(): void
...
@@ -598,13 +637,15 @@ flushSync(): void
...
@@ -598,13 +637,15 @@ flushSync(): void
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
示例:
-
示例:
```
```
storage.flushSync()
storage.flushSync()
```
```
### flush
<sup>(deprecated) </sup>
### flush
flush(callback: AsyncCallback
<
void
>
): void
flush(callback: AsyncCallback
<
void
>
): void
...
@@ -612,6 +653,8 @@ flush(callback: AsyncCallback<void>): void
...
@@ -612,6 +653,8 @@ flush(callback: AsyncCallback<void>): void
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -629,7 +672,7 @@ flush(callback: AsyncCallback<void>): void
...
@@ -629,7 +672,7 @@ flush(callback: AsyncCallback<void>): void
```
```
### flush
<sup>(deprecated) </sup>
### flush
flush(): Promise
<
void
>
flush(): Promise
<
void
>
...
@@ -637,6 +680,8 @@ flush(): Promise<void>
...
@@ -637,6 +680,8 @@ flush(): Promise<void>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
返回值:
-
返回值:
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
...
@@ -644,8 +689,8 @@ flush(): Promise<void>
...
@@ -644,8 +689,8 @@ flush(): Promise<void>
-
示例:
-
示例:
```
```
let promise = storage.flush()
let promise
flush
= storage.flush()
promise.then(() => {
promise
flush
.then(() => {
console.info("Flushed to file successfully.")
console.info("Flushed to file successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Flush to file failed with err: " + err)
console.info("Flush to file failed with err: " + err)
...
@@ -653,7 +698,7 @@ flush(): Promise<void>
...
@@ -653,7 +698,7 @@ flush(): Promise<void>
```
```
### clearSync
<sup>(deprecated) </sup>
### clearSync
clearSync(): void
clearSync(): void
...
@@ -661,13 +706,15 @@ clearSync(): void
...
@@ -661,13 +706,15 @@ clearSync(): void
此方法为同步方法。
此方法为同步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
示例:
-
示例:
```
```
storage.clearSync()
storage.clearSync()
```
```
### clear
<sup>(deprecated) </sup>
### clear
clear(callback: AsyncCallback
<
void
>
): void
clear(callback: AsyncCallback
<
void
>
): void
...
@@ -675,6 +722,8 @@ clear(callback: AsyncCallback<void>): void
...
@@ -675,6 +722,8 @@ clear(callback: AsyncCallback<void>): void
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -692,7 +741,7 @@ clear(callback: AsyncCallback<void>): void
...
@@ -692,7 +741,7 @@ clear(callback: AsyncCallback<void>): void
```
```
### clear
<sup>(deprecated) </sup>
### clear
clear(): Promise
<
void
>
clear(): Promise
<
void
>
...
@@ -700,6 +749,8 @@ clear(): Promise<void>
...
@@ -700,6 +749,8 @@ clear(): Promise<void>
此方法为异步方法。
此方法为异步方法。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
返回值:
-
返回值:
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
...
@@ -707,8 +758,8 @@ clear(): Promise<void>
...
@@ -707,8 +758,8 @@ clear(): Promise<void>
-
示例:
-
示例:
```
```
let promise = storage.clear()
let promise
clear
= storage.clear()
promise.then(() => {
promise
clear
.then(() => {
console.info("Cleared to file successfully.")
console.info("Cleared to file successfully.")
}).catch((err) => {
}).catch((err) => {
console.info("Clear to file failed with err: " + err)
console.info("Clear to file failed with err: " + err)
...
@@ -716,12 +767,14 @@ clear(): Promise<void>
...
@@ -716,12 +767,14 @@ clear(): Promise<void>
```
```
### on('change')
<sup>(deprecated) </sup>
### on('change')
on(type: 'change', callback: Callback
<
StorageObserver
>
): void
on(type: 'change', callback: Callback
<
StorageObserver
>
): void
订阅数据变更者类需要实现StorageObserver接口,订阅的key的值发生变更后,在执行flush/flushSync方法后,callback方法会被回调。
订阅数据变更者类需要实现StorageObserver接口,订阅的key的值发生变更后,在执行flush/flushSync方法后,callback方法会被回调。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 说明 |
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
...
@@ -739,12 +792,14 @@ on(type: 'change', callback: Callback<StorageObserver>): void
...
@@ -739,12 +792,14 @@ on(type: 'change', callback: Callback<StorageObserver>): void
```
```
### off('change')
<sup>(deprecated) </sup>
### off('change')
off(type: 'change', callback: Callback
<
StorageObserver
>
): void
off(type: 'change', callback: Callback
<
StorageObserver
>
): void
当不再进行订阅数据变更时,使用此接口取消订阅。
当不再进行订阅数据变更时,使用此接口取消订阅。
**系统能力**
:SystemCapability.DistributedDataManager.Preferences.Core
-
参数:
-
参数:
| 参数名 | 类型 | 说明 |
| 参数名 | 类型 | 说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
...
@@ -760,7 +815,9 @@ off(type: 'change', callback: Callback<StorageObserver>): void
...
@@ -760,7 +815,9 @@ off(type: 'change', callback: Callback<StorageObserver>): void
```
```
## StorageObserver<sup>(deprecated) </sup>
## StorageObserver
**系统能力**
:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 必填 | 说明 |
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录