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

  

 

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2021-05-09
  • 2021-10-02
  • 2021-07-23
  • 2022-01-04
  • 2021-08-17
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2021-11-11
  • 2021-08-17
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
相关资源
相似解决方案