> - The APIs of this module are no longer maintained since API Version 6. You are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
>
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
## Modules to Import
## Modules to Import
```
```js
importstoragefrom'@system.storage';
importstoragefrom'@system.storage';
```
```
...
@@ -19,7 +19,7 @@ import storage from '@system.storage';
...
@@ -19,7 +19,7 @@ import storage from '@system.storage';
get(Object): void
get(Object): void
Obtains the stored data.
Reads the value stored in the cache based on the specified key.
| key | string | Yes| Index of the data to obtain.|
| key | string | Yes| Key of the data to read.|
| default | string | No| Default value returned when the **key** does not exist.|
| default | string | No| Default value returned when the **key** does not exist.|
| success | Function | No| Called when the stored data is successfully obtained.|
| success | Function | No| Called to return the value obtained when **storage.get()** is successful.|
| fail | Function | No| Called when the stored data failed to be obtained.|
| fail | Function | No| Called when **storage.get()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.get()** is complete.|
**Example**
**Example**
```
```js
exportdefault{
exportdefault{
storageGet(){
storageGet(){
storage.get({
storage.get({
...
@@ -59,7 +59,7 @@ export default {
...
@@ -59,7 +59,7 @@ export default {
set(Object): void
set(Object): void
Modifies the stored data.
Sets the value in the cache based on the specified key.
| key | string | Yes| Index of the data to modify.|
| key | string | Yes| Key of the value to set.|
| value | string | No| New value to set. The maximum length is 128 bytes.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.|
| success | Function | No| Called when the data is successfully modified.|
| success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when the data failed to be modified.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.set()** is complete.|
| success | Function | No| Called when the data is successfully cleared.|
| success | Function | No| Called when **storage.clear()** is successful.|
| fail | Function | No| Called when the data failed to be cleared.|
| fail | Function | No| Called when **storage.clear()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.clear()** is complete.|
**Example**
**Example**
```
```js
exportdefault{
exportdefault{
storageClear(){
storageClear(){
storage.clear({
storage.clear({
...
@@ -131,7 +131,7 @@ export default {
...
@@ -131,7 +131,7 @@ export default {
delete(Object): void
delete(Object): void
Deletes the stored data.
Deletes the key-value pair based on the specified key.
| key | string | Yes| Index of the data to delete.|
| key | string | Yes| Key of the data to delete.|
| success | Function | No| Called when the data is deleted.|
| success | Function | No| Called when **storage.delete()** is successful.|
| fail | Function | No| Called when the data failed to be deleted.|
| fail | Function | No| Called when **storage.delete()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.delete()** is complete.|