這篇文章將為大家詳細講解有關微信小程序中數(shù)據(jù)管理 API的示例分析,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
wx.getStorage(OBJECT)
從本地緩存中異步獲取指定 key 對應的內容。
OBJECT參數(shù)說明:
[tr]參數(shù)類型必填說明[/tr]
key | String | 是 | 本地緩存中的指定的 key |
success | Function | 是 | 接口調用的回調函數(shù),res = {data: key對應的內容} |
fail | Function | 否 | 接口調用失敗的回調函數(shù) |
complete | Function | 否 | 接口調用結束的回調函數(shù)(調用成功、失敗都會執(zhí)行) |
示例代碼:
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) } }) wx.getStorageSync(KEY)
從本地緩存中同步獲取指定 key 對應的內容。
參數(shù)說明:
[tr]參數(shù)類型必填說明[/tr]
key | String | 是 | 本地緩存中的指定的 key |
示例代碼:
try { var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch(e) { // Do something when catch error } wx.getStorageInfo(OBJECT)
異步獲取當前storage的相關信息
OBJECT參數(shù)說明:
[tr]參數(shù)類型必填說明[/tr]
success | Function | 是 | 接口調用的回調函數(shù),詳見返回參數(shù)說明 |
fail | Function | 否 | 接口調用失敗的回調函數(shù) |
complete | Function | 否 | 接口調用結束的回調函數(shù)(調用成功、失敗都會執(zhí)行) |
success返回參數(shù)說明:
[tr]參數(shù)類型說明[/tr]
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 } wx.removeStorage(OBJECT)
從本地緩存中異步移除指定 key 。
OBJECT參數(shù)說明:
[tr]參數(shù)類型必填說明[/tr]
key | String | 是 | 本地緩存中的指定的 key |
success | Function | 是 | 接口調用的回調函數(shù) |
fail | Function | 否 | 接口調用失敗的回調函數(shù) |
complete | Function | 否 | 接口調用結束的回調函數(shù)(調用成功、失敗都會執(zhí)行) |
示例代碼:
wx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) } }) wx.removeStorageSync(KEY)
從本地緩存中同步移除指定 key 。
參數(shù)說明:
[tr]參數(shù)類型必填說明[/tr]
key | String | 是 | 本地緩存中的指定的 key |
示例代碼:
try { wx.removeStorageSync('key') } catch(e) { // Do something when catch error }
關于“微信小程序中數(shù)據(jù)管理 API的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
當前題目:微信小程序中數(shù)據(jù)管理API的示例分析-創(chuàng)新互聯(lián)
文章起源:http://aaarwkj.com/article10/doppdo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、外貿建站、網(wǎng)站策劃、品牌網(wǎng)站建設、面包屑導航、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)