【Session.js】

/*
 * @Author: Jensonhui
 * @Date: 2023-08-28 11:16:26
 * @Description: 本地存储Storage
 */

class storageFn {
  constructor(storage = sessionStorage) {
    this.get = (key) => {
      const item = storage.getItem(key);
      try {
        return JSON.parse(item);
      } catch (error) {
        return item;
      }
    };

    this.set = (key, value) => storage.setItem(key, JSON.stringify(value));

    this.remove = (key) => storage.removeItem(key);

    this.clear = () => storage.clear();
  }
}

export const Session = new storageFn();
export const Application = new storageFn(localStorage);
文章目录