jiqing9006

设置缓存

wx.setStorage({
  key:"key",
  data:"value"
})

移除缓存

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

获取缓存

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

清理缓存

wx.clearStorage()

封装一个Storage

export default {
  set: (data, key = \'userData\') => {
    return wx.setStorageSync(key, data);
  },
  get: (key = \'userData\') => {
    return wx.getStorageSync(key);
  },
  remove: (key = \'userData\') => {
    return wx.removeStorageSync(key);
  },
  clear: () => {
    return wx.clearStorageSync();
  },
  Set: (data, key = \'userData\') => {
    return wx.setStorage({ key, data });
  },
  Get: (key = \'userData\') => {
    return wx.getStorage({ key });
  },
  Remove: (key = \'userData\') => {
    return wx.removeStorage(key);
  },
  Clear: () => {
    return wx.clearStorage();
  }
};

使用封装

import Storage from "./common/auth/Storage";
const storage = Storage.get("userData");
if (!storage) {
	return that.login_register();
}

分类:

技术点:

相关文章:

  • 2022-01-07
  • 2017-11-21
  • 2021-12-02
  • 2021-12-22
  • 2018-04-24
  • 2021-12-06
  • 2021-07-18
猜你喜欢
  • 2021-08-17
  • 2021-08-17
  • 2021-10-17
  • 2021-12-30
  • 2021-08-17
  • 2021-08-17
  • 2021-08-17
相关资源
相似解决方案