title: Taro.getStorage(option)
sidebar_label: getStorage
Asynchronously gets the content of the specified key from the local cache.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property |
Type |
Required |
Description |
| key |
string |
Yes |
The specified key in the local cache |
| complete |
(res: any) => void |
No |
The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail |
(res: any) => void |
No |
The callback function for a failed API call |
| success |
(res: Result) => void |
No |
The callback function for a successful API call |
SuccessCallbackResult
| Property |
Type |
Description |
| data |
any |
Content of the key |
| errMsg |
string |
Call 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
| API |
WeChat Mini-Program |
H5 |
React Native |
| Taro.getStorage |
✔️ |
✔️ |
✔️ |