4-- 微信小程序 缓存

存入缓存  //获取应用实例 const app = getApp()

one

  var info = res.data.info
  app.globalData.info = res.data.info
  wx.setStorageSync('info', app.globalData.info)

two

wx.setStorage({
  key:"info",
  data:app.globalData.info
})

获取缓存

one

	const info = wx.getStorageSync("info");
    var time = util.formatTimeToYmd(info[0].time)
    var faceimg = info[0].faceimg
    var name = info[0].name
    var role = info[0].role
    this.setData({
      info: info,
      time: time,
      faceimg: faceimg,
      name: name,
      role: role
    })
    // time = this.data.time
    // var DATE = util.formatTimeToYmd((new Date());
    // this.setData({
    //   date: DATE,
    // });

two

wx.getStorage({
  key: 'key',
  success (res) {
    console.log(res.data)
  }
})

从本地缓存中移除指定 key

one

wx.removeStorage({
  key: 'key',
  success (res) {
    console.log(res)
  }
})

two

wx.removeStorageSync('key')

清除缓存

    //清除缓存
    clearCache: function(e) {
      wx.clearStorageSync()
      wx.showToast({
        title: '清除完成',
        icon: 'success',
        duration: 2000
      })
    },

猜你喜欢

转载自blog.csdn.net/xu_ze_qin/article/details/106885412