一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

微信小程序实现写入读取缓存的教程

时间:2019-08-30 编辑:猪哥 来源:一聚教程网

在小程序中有些需要把数据缓存到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,
   }
})

热门栏目