微信小程序--数据缓存

小程序数据缓存

wx.setStorageSync
wx.setStorage
wx.getStorage
wx.getStorageSync
wx.clearStorageSync
wx.clearStorage

异步缓存
wx.setStorage
将数据存储在本地缓存中指定的 key 中

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

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

wx.getStorage({
  key: 'key',
  success (res) {
    console.log(res.data)
  }
})

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

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

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

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

同步缓存
wx.setStorageSync(string key, any data)
本地缓存中指定的 key
需要存储的内容。只支持原生类型、Date、及能够通过JSON.stringify序列化的对象
wx.removeStorageSync(string key)
本地缓存中指定的 key
wx.getStorageInfoSync
当前 storage 中所有的 key

清空缓存
wx.clearStorage
清理本地数据缓存
wx.clearStorage()

使用同步存token
在这里插入图片描述
在这里插入图片描述
取token

let token=wx.getStorageSync('token')
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值