var date = newDate().getTime(); //设置localStorage的值 foowwLocalStorage.set("test", "你好", date + 10000); //获取localStorage的值 var data = foowwLocalStorage.get("test");
const foowwLocalStorage = { set: function (key, value, ttl_ms) { var data = { value: value, expirse: newDate(ttl_ms).getTime() }; localStorage.setItem(key, JSON.stringify(data)); }, get: function (key) { var data = JSON.parse(localStorage.getItem(key)); if (data !== null) { debugger if (data.expirse != null && data.expirse < newDate().getTime()) { localStorage.removeItem(key); } else { return data.value; } } returnnull; } }