最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
微信小程序实现写入读取缓存的教程
时间:2022-06-25 15:22:28 编辑:袖梨 来源:一聚教程网
在小程序中有些需要把数据缓存到Storage中,需要的时候在读取缓存中的数据,在微信小程序中通过setStorage写入数据:
wx.setStorage({
key: 'myData',
data: res.data.data
})
通过getStorage读取缓存中的数据:
var that = this;
wx.getStorage({
key: 'myData',
success: function (res) {
var myData = res.data;//读取key值为myData的缓存数据
that.setData({//拿到缓存中的数据并渲染到页面
userName: myData.user.truename,
schoolName: myData.school.name,
className: myData.user.className,
}
})