欢迎光临,了解微信小程序开发,就上易用通!

微信小程序缓存:本地缓存,同步缓存,异步缓存

发布:2017-11-27 17:36浏览: 来源:网络 作者:tianshu

关于本地缓存1.wx.setStorage(wx.setStorageSync)、wx.getStorage(wx.getStorageSync)、wx.clearStorage(wx.clearStorageSync)可以对本地缓存进行设置、获取和清理。本地缓存最大为10 ...

 
 
 


关于本地缓存

1.wx.setStorage(wx.setStorageSync)、wx.getStorage(wx.getStorageSync)、wx.clearStorage(wx.clearStorageSync)可以对本地缓存进行设置、获取和清理。本地缓存最大为10MB

2.localStorage 是永久存储

一、异步缓存

wx.setStorage(OBJECT)

将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容

 

		
  1. wx.setStorage({
  2.  
  3. key:"key",
  4.  
  5. data:"value"
  6.  
  7. })

wx.getStorage(OBJECT)

从本地缓存中异步获取指定 key 对应的内容。

 

		
  1. wx.getStorage({
  2.  
  3. key: 'key',
  4.  
  5. success: function(res) {
  6.  
  7. console.log(res.data)
  8.  
  9. }
  10.  
  11. })

wx.getStorageInfo(OBJECT)

异步获取当前storage的相关信息

 

		
  1. wx.getStorageInfo({
  2.  
  3. success: function(res) {
  4.  
  5. console.log(res.keys)
  6.  
  7. console.log(res.currentSize)
  8.  
  9. console.log(res.limitSize)
  10.  
  11. }
  12.  
  13. })

wx.removeStorage(OBJECT)

从本地缓存中异步移除指定 key 。

 

		
  1. wx.removeStorage({
  2.  
  3. key: 'key',





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。