my.setStorage
Store the data with a specified key in the local cache. This will overlaps\ the original data using the same key.
Supported types of mini programs: DSL, H5+
This is an asynchronous interface.
Support the isolation of webview-embedded storage and the Mini Program storage. Specifying key storage data in embedded webview does not overlap the data corresponding to the same key of the Mini Program itself.
Sample Code
my.setStorage({
key: 'currentCity',
data: {
cityName: 'London',
adCode: '330100',
spell: ' London',
},
success: function() {
my.alert({content: 'Set Success'});
}
});Parameters
| Property | Type | Required | Description |
| key | String | Yes | Cache data key. |
| data | Object | Yes | Data to be cached. |
| success | Function | No | Callback function upon call success. |
| fail | Function | No | Callback function upon call failure. |
| complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Note: When a single data is converted into a string, the string length is maximum 200*1024. For the same user, the cache of one Mini Program has an upper limit 10MB.
Error Code
Error Code | Error message | Further action |
2 | Required parameter is empty | Make sure the data type of the |
12 | Maximum storage | The data storage limit for a single mini program is 10 MB. Use the my.removeStorage JSAPI to clear unnecessary data. |
13 | Storage failure | Failed to store the data in the local cache. Please try again later. |
14 | Data length overrun | The maximum data size allowed for a single key is 200 KB. Please reduce the data length or split it into multiple keys. |