使用緩存: (設置緩存,儘可能用大寫,下劃線的寫法)緩存
const ls = { set: function (variable, value, ttl_ms) { var data = {value: value, expires_at:new Date(ttl_ms).getTime()}; localStorage.setItem(variable.toString(), JSON.stringify(data)); }, get: function (variable) { var data = JSON.parse(localStorage.getItem(variable.toString())); if (data !== null) { debugger if (data.expires_at !== null && data.expires_at < new Date().getTime()) { localStorage.removeItem(variable.toString()); } else { return data.value; } } return null; } }; window.ls = ls; //使用方式 let _CRM_COMMENT_GUIDE = ls.get("CRM_COMMENT_GUIDE"); ls.set("CRM_COMMENT_GUIDE",true,deadLine);