localStorage 和 sessionStorage 基本用法基本一致;localStorage需要会长时间保存,而sessionStorage会保存在当前对话框,会随着浏览器的关闭而被清除,
存储的数据格式必须是string;所以当localStorage.setItem(a,b)时,不管b为何种数据,在存储时都会被强制转化为string格式,进而在拿取getItem(a)时得到的永远是字符串,
存储:
localStorage.setItem('obj', JSON.stringify(对象))
获取
JSON.parse(localStorage.getItem('obj'))