小程序異步獲取當前storage的相關信息wx.getStorageInfo
wx.getStorageInfo(Object object)
異步獲取當前storage的相關信息。緩存相關策略請查看 存儲。
以 Promise 風格 調用:支持
小程序插件:不支持
微信 Windows 版:支持
微信 Mac 版:支持
參數
Object object
屬性 類型 默認值 必填 說明
success function 否 接口調用成功的回調函數
fail function 否 接口調用失敗的回調函數
complete function 否 接口調用結束的回調函數(調用成功、失敗都會執行)
object.success 回調函數
參數
Object object
屬性 類型 說明
keys Array.<string> 當前 storage 中所有的 key
currentSize number 當前占用的空間大小, 單位 KB
limitSize number 限制的空間大小,單位 KB
示例代碼
wx.getStorageInfo({
success (res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
try {
const res = wx.getStorageInfoSync()
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
} catch (e) {
// Do something when catch error
}