setStorage、getStorage、 removeStorage 封装
2024-10-08 00:24:57
// 本地存储
setStorage(name, data){
let dataType = typeof data;
// json对象
if(dataType === 'object'){
window.localStorage.setItem(name, JSON.stringify(data));
}
// 基础类型
else if(['number','string','boolean'].indexOf(dataType) >= 0){
window.localStorage.setItem(name, data);
}
// 其他不支持的类型
else{
alert('该类型不能用于本地存储');
}
}
// 取出本地存储内容
getStorage(name){
let data = window.localStorage.getItem(name);
if(data){
return JSON.parse(data);
}
else{
return '';
}
}
// 删除本地存储
removeStorage(name){
window.localStorage.removeItem(name);
}
最新文章
- eclispe+axis2+webservice入门
- input 放大镜
- javascript--Function
- C语言中scanf()的用法!
- MySQL对于数据库应该如何如何配置安全问题了
- 【转】使用C#实现ADSL自动拨号
- SQLite数据库简介(转)
- git ssh认证
- Docker私有仓库Registry 搭建
- CF908D Arbitrary Arrangement
- Python菜鸟快乐游戏编程_pygame(3)
- PyCharm下载及使用
- Linux 环境 Maven 安装&;仓源配置
- JAVA常用工具类汇总
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
- applyColorMap()研究(如果我对现有的colormap不满意,那么如何具体来做)
- 分割(partition,stable_partition)
- SVN previous operation has not finished
- js中的深层复制
- Cookie、Session、Token