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