微信 数据缓存方法 的区别

wx.setStorageSync

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

wx.setStorageSync('key','my first')
wx.setStorage()

wx.setStorageSync 的异步方法

 wx.setStorage({
      key: "key",
      data: "my first"
    })
wx.removeStorageSync

从本地缓存中移除指定 key

wx.removeStorageSync('key')
wx.removeStorage

wx.removeStorageSync 的异步版本

wx.removeStorage({
      key: 'key',
      success: function(res) {
        console.log(res)
      }
    })
wx.getStorageSync

获取本地缓存中设置的value

wx.getStorageSync('key')
wx.getStorage()

wx.getStorageSync 的异步版本

    wx.getStoragein({
      key: 'key',
      success: function(res) {
        console.log(res)
      }
    })
wx.getStorageInfoSync()

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

  let info = wx.getStorageInfoSync()
  console.log(info)

在这里插入图片描述

wx.getStorageInfo()

wx.getStorageInfoSync()的异步版本

wx.getStorageInfo({
	success (res) {}
})
wx.clearStorage()

清除storage 所有的内容

wx.clearStorage()
wx.clearStorageSync()

wx.clearStorage 的同步版本

 wx.clearStorageSync()
发布了16 篇原创文章 · 获赞 10 · 访问量 1032

猜你喜欢

转载自blog.csdn.net/qq_39557024/article/details/105098767