1、同一个微信用户,同一个小程序 缓存上限为 10MB。同一台设备上,A 用户无法读取到 B 用户的数据。所以不用担心多用户单手机登录的问题。
2、异步存储的函数, wx.setStorage({ //异步存储到缓存当中 key: "name", data: "xiaoming" })
3、wx.getStorage({//异步取出缓存的值 key: 'name', success: function (res) { console.log(res.data) } })
4、wx.removeStorage({//异步删除缓存 key: 'name', success: function (res) { console.log(res.data) } })
5、同步存储,取出,删除。代码:try {//同步存储 wx.setStorageSync('key', 'value') } catch (e) { } try {//同步取出 var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch (e) { // Do something when catch error } try {//同步移除 wx.removeStorageSync('key') } catch (e) { // Do something when catch error }