【Vue/js】通过localStorage浏览器实现变量和对象的本地缓存(图文+完整源代码)
2023-09-11 14:14:57 时间
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>demo</title>
</head>
<body>
<div id="box">
<h2>通过localStorage把变量或对象存入浏览器缓存</h2>
<button onclick="save()"> 存入浏览器</button>
<button onclick="get()"> 调取浏览器参数</button>
</div>
</body>
<script type="text/javascript">
function save() {
let p = { name: '张三丰', sex: '男' }
localStorage.setItem('username', 'csj')
localStorage.setItem('userId', '10010')
localStorage.setItem('info', JSON.stringify(p))
}
function get() {
console.log('=============')
console.log('username:'+localStorage.getItem('username'))
console.log('userId:'+localStorage.getItem('userId'))
console.log('info:'+JSON.parse(localStorage.getItem('info')).name)
let p = { name: '张三丰', sex: '男' }
localStorage.setItem('username', 'csj')
localStorage.setItem('userId', '10010')
localStorage.setItem('info', JSON.stringify(p))
}
</script>
</html>
相关文章
- Vue_(组件通讯)使用solt分发内容
- JS框架_(JQuery.js)网页文字评论弹幕
- Vue -> 解决 vue-ueditor-wrap 不能显示的问题
- VUE - vue.runtime.esm.js?6e6d:619 [Vue warn]: Do not use built-in or reserved HTML elements as component i
- vue-cli3父子组件传值
- vue typescript .eslintrc.js
- [Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js
- vue.js3:使用clipboard.js实现复制到剪贴板(vue@3.2.37 / clipboard@2.0.11)
- Vue.js3: 页面打开前实现图片全部预加载(vue@3.2.33)
- vue.js项目在nginx上部署:使spring后端记录真实ip地址
- vue 实站技巧总结
- [Vue + TS] Watch for Changes in Vue Using the @Watch Decorator with TypeScript
- [Vue-rx] Handle Image Loading Errors in Vue.js with RxJS and domStreams
- [Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js
- [Vue] Get up and running with vue-router
- [Vue] Conditionally Render DOM Elements in Vue.js (v-if v-else v-show)
- vue事件修饰符:@click.capture捕获内层事件,从而改变默认的冒泡执行顺序
- 手摸手带你用实现vue全屏loading插件
- Atitit 项目界面h5化静态html化计划---vue.js 把ajax获取到的数据 绑定到表格控件 v2 r33.docx
- vue项目router-link怎样获取动态路由怎样传参?怎样获取/:id的值?
- vue学习资料:vue笔记ppt整理(vue基础指令&vue基础语法)
- vue 音频播放切换后还播放原来播放源
- 解决springboot+vue+mybatis中,将后台数据分页显示在前台,并且根据页码自动跳转对应页码信息
- Springboot+Vue实现将图片和表单一起提交到后端,同时将图片地址保存到数据库、再次将存储的图片展示到前端vue页面
- vue-cli打包之后的项目在nginx的部署
- Vue中data元素之间相互赋值的陷阱
- 142:vue+openlayers 测量长度和面积,modifyend后更改数值
- 053:vue+openlayers使用setPosition来定位弹窗(示例代码)
- 前端必备技能知识:JS导出Blob流文件为Excel表格、Vue.js使用Blob的方式实现excel表格的下载(流文件下载)
- 声纹可视化工具:wavesurfer.js---在Vue中使用音频声纹可视化插件wavesurfer.js【已封装成组件有完整demo实例附完整代码】
- springboot+jwt+shiro+vue+elementUI+axios+redis+mysql简易博客项目