小程序- 基础知识之本地缓存

 

 

1.异步设置本地缓存wx.setStorage、wx.setStorageSync
异步获取本地存储  wx.getStorage、wx.getStorageSync
异步清空本地存储  wx.clearStorage、wx.getStorageSync
可以对本地缓存进行设置、获取和清理。本地缓存最大为10MB
2.localStorage是永久存储

一、异步缓存

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

wx.setStorage({
  key:"key",
  data:"value"
})

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

wx.getStorage({
  key:"value",
  success:function(res){
    console.log(res.data)
  }
})

wx.getStorageInfo 异步获取当前Storage的相关信息

wx.getStorageInfo({
  success:function(res){
    console.log(res.keys)
    console.log(res.currentSize)
    console.log(res.limitSize)
  }
})

wx.removeStorage 从本地缓存中异步移除指定key
 

wx.removeStorage({
  key:"key",
  success:function(res){
    console.log(res.data)
  }
})


 


版权声明:本文为u012485897原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。