title: Taro.setStorage(option)

sidebar_label: setStorage

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.

Reference

Type

  1. (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

  1. Taro.setStorage({
  2. key:"key",
  3. data:"value"
  4. })
  1. try {
  2. Taro.setStorageSync('key', 'value')
  3. } catch (e) { }

API Support

API WeChat Mini-Program H5 React Native
Taro.setStorage ✔️ ✔️ ✔️