從本地緩存中異步獲取指定 key 對應的內容。
OBJECT參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
key | String | 是 | 本地緩存中的指定的 key |
success | Function | 是 | 接口調用的回調函數,res = {data: key對應的內容} |
fail | Function | 否 | 接口調用失敗的回調函數 |
complete | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |
示例代碼:
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) } })
從本地緩存中同步獲取指定 key 對應的內容。
參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
key | String | 是 | 本地緩存中的指定的 key |
示例代碼:
try { var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch (e) { // Do something when catch error }
異步獲取當前storage的相關信息
OBJECT參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
success | Function | 是 | 接口調用的回調函數,詳見返回參數說明 |
fail | Function | 否 | 接口調用失敗的回調函數 |
complete | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |
success返回參數說明:
參數 | 類型 | 說明 |
---|---|---|
keys | String Array | 當前storage中所有的key |
currentSize | Number | 當前占用的空間大小, 單位kb |
limitSize | Number | 限制的空間大小,單位kb |
示例代碼:
wx.getStorageInfo({ success: function(res) { console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) } }) ### wx.getStorageInfoSync 同步獲取當前storage的相關信息 **示例代碼:** ```javascript try { var res = wx.getStorageInfoSync() console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) } catch (e) { // Do something when catch error }
從本地緩存中異步移除指定 key 。
OBJECT參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
key | String | 是 | 本地緩存中的指定的 key |
success | Function | 是 | 接口調用的回調函數 |
fail | Function | 否 | 接口調用失敗的回調函數 |
complete | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |
示例代碼:
wx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) } })
從本地緩存中同步移除指定 key 。
參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
key | String | 是 | 本地緩存中的指定的 key |
示例代碼:
try { wx.removeStorageSync('key') } catch (e) { // Do something when catch error }