第10课 微信小程序数据存储(同、异步缓存,本地读取缓存):
- 同步缓存:wx.setStorageSync(key, value)
- 异步缓存:wx.setStorage(Object object)
- 同步删除缓存:wx.removeStorageSync(key)
- 异步删除缓存:wx.removeStorage(Object object)
- 同步获取缓存: wx.getStorageSync(key)
- 异步获取缓存: wx.getStorage(key)
- 同步查询缓存: wx.getStorageInfoSync(string key)
- 异步查询缓存: wx.getStorageInfo(Object object)
- 同步清空缓存:wx.clearStorageSync()
- 异步清空缓存:wx.clearStorage(Object object)
同步缓存:wx.setStorageSync(key, value)
异步缓存:wx.setStorage(Object object)
同步缓存数据与获取数据实现代码:
Page({
data: {
name:["张三","李四","王五","重八"]
},
onLoad: function (options) {
//同步缓存数据
wx.setStorageSync("name", this.data.name)
//同步获取数据
let data1 = wx.getStorageSync('name')
console.log(data1)
},
})