zhengnaiwen_citu 1 vuosi sitten
vanhempi
commit
02a858795f
1 muutettua tiedostoa jossa 3 lisäystä ja 5 poistoa
  1. 3 5
      src/hooks/web/useDictionaries.js

+ 3 - 5
src/hooks/web/useDictionaries.js

@@ -14,11 +14,9 @@ const setDict = (type, val, cacheTime) => {
 
 export const getDict = (type) => {
     return new Promise((resolve) => {
-      const catchData = localStorage.getItem(type)
-      if (!catchData) {
-        return
-      }
-      if (catchData.expire && (Date.now() <= catchData.expire)) {
+      const item = localStorage.getItem(type)
+      const catchData = item ? JSON.parse(item) : null
+      if (catchData && catchData.expire && (Date.now() <= catchData.expire)) {
         return resolve(catchData.data)
       }
       // 传参按照规范参数传