缓存localStorage

最近做项目的时候,需要用到缓存,把表单填写的部分数据存入缓存,下次进入的时候先取缓存

对象操作:

user:{
id:1,
name:"xx"
}
var window=localStorage;
window.setItem("user",user);//存入对象
window.getItem("user");

window.setItem("id",id);//存入某个属性
window.getItem("id");

list操作

id:1,
id:2,
id:3,
 var list = new Array();
list.push(1);
list.push(2);
list.push(3);
//存入
list.JSON.parse(localStorage.setItem('list',list)) //一定要转换一下
//取出来
list.JSON.parse(localStorage.getItem('list'))

猜你喜欢

转载自blog.csdn.net/oschina_41661541/article/details/86490357
今日推荐