schangxiang@126.com
2025-04-17 37184b1d1ac000a6ee40e397e2336b213e705902
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class LocalCache {
  setCache(key: string, value: any) {
    window.localStorage.setItem(key, JSON.stringify(value));
  }
  getCache(key: string) {
    const value = window.localStorage.getItem(key);
    if (value) {
      let obj = ''
      try {
        obj = JSON.parse(value)
      } catch (err) {
        obj = value
      }
      // console.log(obj);
      return obj
    } else {
      return '';
    }
  }
  deleteCache(key: string) {
    window.localStorage.removeItem(key);
  }
  clearCache() {
    window.localStorage.clear();
  }
}
 
export default new LocalCache();