封装缓存公共方法

2021-09-26  本文已影响0人  Rascar
//新建一个 cache.js 
//将 CacheStorage  导出
class CacheStorage {
  loaceSet(name, value) {
    window.localStorage.setItem(name, JSON.stringify(value));
  }
  loaceGet(name) {
    let value = window.localStorage.getItem(name);
    if (value) {
      return JSON.parse(value);
    }
  }
  //指定删除
  delectLactGet(name) {
    localStorage.removeItem(name);
  }
  // 全部删除
  romeAllClear() {
    localStorage.clear();
  }
}
export default new CacheStorage();
上一篇 下一篇

猜你喜欢

热点阅读