# wx.setStorage(Object object)
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.
# Parameters
# Object object
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
key | string | Yes | The specified key in the local cache | |
data | any | Yes | Contents to be stored can only be native types, dates, and objects that can be serialized via JSON.stringify . | |
success | function | No | The callback function for a successful API call | |
fail | function | No | Callback function for failed API call | |
complete | function | No | Callback function used when API call completed (always executed whether call succeeds or fails) |
# Sample Code
wx.setStorage({
key:"key",
data:"value"
})
try {
wx.setStorageSync('key', 'value')
} catch (e) { }