存储数据到本地
const info = {
name: 'Lee',
age: 20,
id: '001'
};
//key是存储的数据名称,后面的info是存的数据,存的是字符串类型的
var data1=localStorage.setItem('key', JSON.stringify(info));
var data2=sessionStorage.setItem('name',JSON.stringify(info));
从本地获取数据
//获取到的数据是字符串要转换成对象才能用
var data1=JSON.parse(localStroage.getItem('key'));
var data2=JSON.parse(sessionStroage.getItem('name));
删除本地存储的某个数据
localStroage.removeItem('key');
sessionStorage.removeItem('name');
清除本地存的所有数据
localStroage.clear();
sessionStorage.clear();