当前位置:网站首页>52-localStorage本地存储
52-localStorage本地存储
2022-07-19 05:05:00 【longfei815】
52-localStorage本地存储
// 保存数据,以字符串的形式保存数据
// localStorage.setItem(数据名,值)
// localStorage.setItem('name','Vue')
// localStorage.setItem('age',8)
// 获取数据
// console.log(localStorage.getItem('name')); // 数据还存在
// console.log(localStorage.getItem('age'));
// 指定删除
// localStorage.removeItem('age')
// 清空数据
// localStorage.clear
<!DOCTYPE html>
<html lang="en">
<head>
<title>52-localStorage本地存储</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link href="css/style.css" rel="stylesheet"> -->
<script>
// 保存数据,以字符串的形式保存数据
// localStorage.setItem(数据名,值)
// localStorage.setItem('name','Vue')
// localStorage.setItem('age',8)
// 获取数据
// console.log(localStorage.getItem('name')); // 数据还存在
// console.log(localStorage.getItem('age'));
// 指定删除
// localStorage.removeItem('age')
// 清空数据
// localStorage.clear
let obj = {
name:'Vue',
age:8
}
// 如果保存的是对象,需要通过JSON.stringify转化成字符串,
// 取出的时候需要通过JSON.parse转化成对象。
localStorage.setItem('obj',JSON.stringify(obj))
console.log(JSON.parse(localStorage.getItem('obj')).name);
console.log(JSON.parse(localStorage.getItem('obj')).age,typeof JSON.parse(localStorage
.getItem('obj')).age);
// typeof作用:是查看前面数据的类型。
</script>
</head>
<body>
</body>
</html>
边栏推荐
- Pointer operation exercises and string functions
- Jenkins linked flybook pushes the test report notification message in the form of signature verification
- 更易上手的C语言入门级芝士 (2) 选择语句+循环语句、函数、数组、操作符(超详细)
- Data tower problem and deformation
- 数组的 reduce方法
- Pytorch target detection data enhances the mixing of cutmix and mixup
- 【学习笔记】Solid Works 作业记录
- Greedy - deletion
- 字符函数和字符串函数
- 学习日记-指针专题
猜你喜欢
随机推荐
第七十四篇:机器学习优化方法及超参数设置综述
c语言自定义类型:结构体、枚举、联合
C language custom types: structure, enumeration, union
【学习笔记】Solid Works 作业记录
shell脚本编程
[调试bug]JS:getFullYear is not a function
位运算——异或
77-全局自定义指令
C语言中的文件操作
Interval coverage problem
第五十九篇:main.c:62:9: note: use option -std=c99 or -std=gnu99 to compile your code
[Day.2]约瑟夫环问题,如何用数组代替循环链表(详解)
第七十二:行人检测
Promise 解决回调地狱、async await 修饰符
堆堆排序及堆的相关操作
递归回溯—走迷宫
Skillfully solve Young's matrix
Esp8266 -- temperature and humidity monitoring code dht-11 (web page display)
已故苹果联合创始人乔布斯被追授美国总统自由勋章
The longest common subsequence of order 2 and order n