setExpire(key, value, expired) {
let obj = {
data: JSON.stringify(value),
time: Date.now(),
expire: expired
};
localStorage.setItem(key, JSON.stringify(obj));
},
getExpire(key) {
let val = localStorage.getItem(key);
if (!val) {
return null;
}
val = JSON.parse(val);
if (Date.now() - val.time > val.expire) {
localStorage.removeItem(key);
return null;
}
return JSON.parse(val.data);
},
localStorage加过期时间
最新推荐文章于 2023-03-03 15:50:59 发布