微信小程序数据缓存
每個微信小程序都可以有自己的本地緩存同一個微信用戶,同一個小程序 storage 上限為 10MB。
| 操作 | 異步方法 | 同步方法 |
| 插入 | wx.setStorage | wx.setStorageSync |
| 讀取 | wx.getStorage | wx.getStorageSync |
| 刪除 | wx.removeStorage | wx.removeStorageSync |
| 清空 | wx.clearStorage | wx.clearStorageSync |
| 獲取當前緩存信息 | wx.getStorageInfo | wx.getStorageInfoSync |
示例代碼:
wx.setStorage({key:"key",data:"value" }) try {wx.setStorageSync('key', 'value') } catch (e) { } wx.getStorage({key: 'key',success: function(res) {console.log(res.data)} }) try {var value = wx.getStorageSync('key')if (value) {// Do something with return value} } catch (e) {// Do something when catch error } wx.getStorageInfo({success: function(res) {console.log(res.keys)console.log(res.currentSize)console.log(res.limitSize)} }) 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({key: 'key',success: function(res) {console.log(res.data)} }) try {wx.removeStorageSync('key') } catch (e) {// Do something when catch error } wx.clearStorage() try {wx.clearStorageSync() } catch(e) {// Do something when catch error }創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
- 上一篇: 乐理基础知识入门(学唱歌史上最全基础)
- 下一篇: NATAPP.CN 内网穿透教程