export default{ set(key,data,time){ let obj={ data=data, ctime:(new Date()).getTime(),//时间戳,同Date.now() express:1000*60*60//设置过期时间一个小时 } localStorage.setItem(key,JSON.stringify(obj)); }, get(key){ let obj=JSON.parse(localStorage.getItem(key)); let getItem=(new Date()).getTime(); if(getItem-obj.ctime>=express){ localStorage.removeItem(key); return null; }else{ return obj.data; } } }
原文地址:https://www.cnblogs.com/wuqilang/p/11450963.html
时间: 2024-10-10 17:08:28