获取数据
//获取数据
let arr=JSON.parse(localStorage.getItem('goods')) || []
存储数据
//定义一个对象
const data={
name:'小红',
age:20
}
//存储数据
localStorage.setItem('goods', JSON.stringify(data))
Vue中本地存储
data(){
return{
list:JSON.parse(localStorage.getItem('list'))||[
{id:1,name:'打篮球'},
{id:2,name:'看电影'},
{id:3,name:'打台球'}
]
}
}
//深度监视数据变化,便本地存储
watch:{
list:{
deep:true,
handler(newValue){
localStorage.setItem('list',JSON.stringify(newValue))
}
}
}

916

被折叠的 条评论
为什么被折叠?



