my.setStorage
Store the data with a specified key in the local cache. This will overlaps\ the original data using the same key.
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.The cached data are user isolated, which means if user logs out wallet and logs in as a different user, the mini program will not be able to get previous user's cached data.
Sample Code
copy
my.setStorage({
key: 'currentCity',
data: {
cityName: 'London',
adCode: '330100',
spell: ' London',
},
success: function() {
my.alert({content: 'Set Success'});
}
});
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
key | String | Yes | Cache data key |
data | Object/String | 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.