Taro.setStorage(option)
Stores data in the specified key in the local cache. This operation will overwrite the original content of the key. The data storage lifecycle is consistent with the Mini Program, that is, data is always available unless manually deleted by the user or automatically deleted after a certain period of time. The maximum size of data stored in a single key is 1 MB, and the total size for data storage is limited to 10 MB.
Type
(option: Option) => Promise<CallbackResult>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
data | any | Yes | Contents to be stored can only be native types, dates, and objects that can be serialized via JSON.stringify . |
key | string | Yes | The specified key in the local cache |
complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void | No | The callback function for a failed API call |
success | (res: Result) => void | No | The callback function for a successful API call |
Sample Code
Taro.setStorage({
key:"key",
data:"value"
})
try {
Taro.setStorageSync('key', 'value')
} catch (e) { }
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.setStorage | ✔️ | ✔️ | ✔️ |