Skip to main content
Version: 3.x

Taro.getStorage(option)

Asynchronously gets the content of the specified key from the local cache.

Reference

Type

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
keystringYesThe specified key in the local cache
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
dataanyContent of the key
errMsgstringCall result

Sample Code

Taro.getStorage({
key: 'key',
success: function (res) {
console.log(res.data)
}
})
try {
var value = Taro.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getStorage✔️✔️✔️