小程序实现写入缓存与读取缓存

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

  

 

posted on 2019-08-29 14:25  婧星  阅读(3027)  评论(0编辑  收藏  举报

导航