單個密鑰容許存儲的最大數據長度爲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 }