localStorage页面传值

  • Post author:
  • Post category:其他


1.在需要传值页面储存

//对象
let numberarr = { num1: 1, num2: 2, num3: 3 };
//字符串
let str = 'heoll';
localStorage.setItem('numberarr ', JSON.stringify(numberarr ));
localStorage.setItem('str', str);

2.在另一页面获取

let numb = JSON.parse(localStorage.getItem('number'));

let strarr = localStorage.getItem('str');

3.删除

//删除某个

localStorage.removeItem('nubmer');

//删除所有

localStorage.clear();



版权声明:本文为fan1321923530原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。