SOURCE

const store = {
    setItem(key, value, time) {
        window.localStorage.setItem(key, JSON.stringify({
            value: JSON.stringify(value),
            time: Date.now(),
            expire: time
        }))
    },
    getItem(key) {
        const obj = JSON.parse((window.localStorage.getItem(key) || "{}"))
        if (!obj.value || Date.now() > obj.time + obj.expire) {
            return window.localStorage.removeItem(key)
        }
        return obj.value;
    }
}

// store.setItem('name', 'zs', 1000)
console.log(store.getItem('name'))
console 命令行工具 X clear

                    
>
console