从本地缓存中异步获取指定 key 对应的内容
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) } , fail: function(){}, complete: function(){} })将 data 存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个同步接口
try { wx.setStorageSync('key', 'value') } catch (e) { }从本地缓存中异步获取指定 key 对应的内容
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) }, fail: function(){}, complete: function(){} })从本地缓存中同步获取指定 key 对应的内容
try { var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch (e) { // Do something when catch error }异步获取当前storage的相关信息
wx.getStorageInfo({ success: function(res) { console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) }, fail: function(){}, complete: function(){} })同步获取当前storage的相关信息
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
wx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) }, fail: function(){}, complete: function(){} })从本地缓存中同步移除指定 key
try { wx.removeStorageSync('key') } catch (e) { // Do something when catch error }清理本地数据缓存
wx.clearStorage()同步清理本地数据缓存
try { wx.clearStorageSync() } catch(e) { // Do something when catch error } 本地数据缓存大小限制为10MB。