localStorage 持久化的存储,不会因为界面的刷新或者重启浏览器而消失,除非清除缓存
用途【vue】
vueX会因为界面的刷新而丢失数据,通过localStorage存储可以避免
通过 "名/键"的方式存储在浏览器中
使用
localStorage.setItem('fontSize', 15)
localStorage.getItem('fontSize')
存放对象 以JSON格式存放 不受页面刷新影响
localStorage.setItem('user',JSON.stringify({name:'张三',age:'18'}))
JSON.parse(localStorage.getItem('users'))