dlt.setStorage
Introduction
Stores data in the specified key in the local cache. It will overwrite the content corresponding to the key unless the user actively deletes it or the system clears it due to storage space reasons. The data will be available until it is deleted by the user or cleared by the system.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
key | string | Yes | The key in the local cache where the data will be stored. | |
data | string | Yes | The data to be stored. Only native types, Date, and objects that can be serialized using JSON.stringify are supported. | |
success | function | No | Callback function for a successful API call. | |
fail | function | No | Callback function for a failed API call. | |
complete | function | No | Callback function that will be executed when the API call is complete (both successful and failed calls). |
success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - Set successfully. |
fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | false - Set failed. |
Example Code
// pages/index/index.js
Page({
setStorage() {
dlt.setStorage({
key: "xxx",
data: "data",
success: function () {
console.log("setStorage success");
},
});
},
});