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.

Sample Code

copy
my.setStorage({
  key: 'currentCity',
  data: {
    cityName: 'London',
    adCode: '330100',
    spell: ' London',
  },
  success: function() {
    my.alert({content: 'Set Success'});
  }
});

Parameters

PropertyType

Required

Description
keyStringYesCache data key.
dataObject/StringYesData to be cached.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback 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.