使用 localstorage 写入浏览器并获取

 

写入:以字符串的形式写入

 localStorage.setItem('data', JSON.stringify(arr));

 

使用 localstorage 写入浏览器并获取

 

获取:

注意:一定要使JSON.parse转为对象才能取出来,不然是空的

const data1 = localStorage.getItem('data');
     var data = JSON.parse(data1); //取出来的字符串在转化为对象JSON.parse对象
           
console.log(data[0].productName);

 

使用 localstorage 写入浏览器并获取

 

posted @ 2019-03-04 14:45 梓鸿 阅读(...) 评论(...) 编辑 收藏

相关文章:

  • 2021-12-25
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-10-21
  • 2021-11-19
  • 2021-11-29
  • 2021-08-26
猜你喜欢
  • 2021-12-31
  • 2021-05-05
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案