单个密钥容许存储的最大数据长度为1MB,全部数据存储上限为10MB。缓存
// 存储信息到storage // 异步存储 set() { wx.setStorage({ key: 'user', data: 'cck', success: ()=> { console.log('存储成功'); } }) }, // 同步存储 set() { try { wx.setStorageSync('user', 'cck') } catch (e) { } }
从本地缓存中异步获取指定key的内容异步
// 异步 wx.getStorage({ key: 'user', success (res) { console.log(res.data) } }) // 同步 try { var value = wx.getStorageSync('user') if (value) { // Do something with return value } } catch (e) { // Do something when catch error }
从本地缓存中移除指定 key大数据
// 异步 wx.removeStorage({ key: 'user', success (res) { console.log(res.data) } }) // 同步 try { wx.removeStorageSync('user') } catch (e) { // Do something when catch error }