title: Taro.getStorageInfo(option)

sidebar_label: getStorageInfo

Asynchronously gets the information related to the current storage.

Reference

Type

  1. (option?: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
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

SuccessCallbackOption

Property Type Description
currentSize number Current space occupied (in KB)
keys string[] All keys in the current storage
limitSize number Space size limit (in KB)

Sample Code

  1. Taro.getStorageInfo({
  2. success: function (res) {
  3. console.log(res.keys)
  4. console.log(res.currentSize)
  5. console.log(res.limitSize)
  6. }
  7. })
  1. try {
  2. const res = Taro.getStorageInfoSync()
  3. console.log(res.keys)
  4. console.log(res.currentSize)
  5. console.log(res.limitSize)
  6. } catch (e) {
  7. // Do something when catch error
  8. }

API Support

API WeChat Mini-Program H5 React Native
Taro.getStorageInfo ✔️ ✔️ ✔️