/**
-
Public methods for localStorage and sessionStorage
-
Created by XuXiaochuan on 2021/04/26.
/
class Store {
/*- @function 构造函数
- @param {Object} store window的存储对象(localstorage、sessionStorage)
*/
constructor(store) {
// 检测是否支持localstorage
if (!store) {
return
}
this._store = store
}
/**
- @function 带过期时间存值
- @param {String} key 名称
- @param {any} value 值
- @param {Number} expire 过期时间(毫秒)
*/
setExpire(key, value, expire){
if (!this._store) return
let obj = {
data: value,
time: Date.now(),
expire: expire
};
//localStorage 设置的值不能为对象,转为json字符串
this._store.setItem(key, JSON.stringify(obj));
}
/**
- @function 带过期时间取值(过期删