Storage APIs

getStorage

Get cached data from local storage by key.

Overview

my.getStorage retrieves cached data from local storage. This is an asynchronous interface that supports isolation between embedded webview cache and Mini Program cache. Getting the cache of the specified key of embedded webview will not return the cached data of the same key of the Mini Program.

Sample Code

my.getStorage({
  key: 'currentCity',
  success: function(res) {
    my.alert({content: 'Success' + res.data.cityName});
  },
  fail: function(res){
    my.alert({content: res.errorMessage});
  }
});

Parameters

PropertyTypeRequiredDescription
keyStringYesCache data key.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
dataObject/StringCorresponding content of the key.

Usage Notes

  • This is an asynchronous interface
  • Storage is isolated between embedded webview and Mini Program
  • Retrieve data using the same key that was used in my.setStorage