当前位置:网站首页>【无标题】
【无标题】
2022-08-01 15:16:00 【baoleilei6】
const localStorage = window.localStorage || {};
class Local {
static setItem(key, data) {
if (Object.prototype.toString.apply(data) == "[object Object]" || Object.prototype.toString.apply(data) == '[object Array]') {
data = JSON.stringify(data);
}
localStorage[key] = data;
}
static getItem(key) {
let value = localStorage[key] || null;
if (value) {
try {
value = JSON.parse(value);
} catch (e) {
// console.warn(e)
}
}
return value;
}
static removeItem(key) {
localStorage.removeItem(key);
}
static get enable() {
if (!window.localStorage) return false;
let e = true;
try {
window.localStorage.setItem("test", 1);
} catch (err) {
e = false;
}
return e;
}
}
export default Local;
边栏推荐
猜你喜欢
随机推荐
你真的会测试用户登录吗?
pynlpir更新license Error: unable to fetch newest license解决方案
eslint语法报错解决
向mysql 传数据 这个字符串长度有限制么
如何快速将Zabbix5.0升级至6.0?
leetcode:33. 搜索旋转排序数组
Bloom filter bloom
到底什么才是真正的商业智能(BI)
LeetCode50天刷题计划(Day 7—— 字符串转换整数 (atoi) 12.20-15.20)
测试如何拓展自己的知识面?
Inflation continues, Kenya's food security a concern
搭建ntp时间服务器(安装sql2000配置服务器失败)
leetcode:80. 删除有序数组中的重复项 II
c语言rand函数生成随机数,详解C语言生成随机数rand函数的用法[通俗易懂]
细读《阿里测试之道》
全网最全音视频媒体流
预定义和自定义
游戏元宇宙发展趋势展望分析
阿里巴巴测试开发岗P6面试题
【LeetCode】37、解数独