当前位置:网站首页>localstorage本地存储的方法
localstorage本地存储的方法
2022-08-04 17:44:00 【哈希嘻哈】
通常我们把用户信息存储到仓库中时,刷新后信息会丢失。一般还会再存储到本地。
方法如下:
其中Profile是用户信息类型注解
import {
Profile} from '@/types/user'
const key = 'my_key'
// 存储用户信息
export const setUserInfo = (userInfo: Profile) => {
localStorage.setItem(key, JSON.stringify(userInfo))
}
// 获取用户信息
export const getUserInfo = () => {
return JSON.parse(localStorage.getItem(key) || '{}')
}
// 移除用户信息
export const removeUserInfo = () => {
localStorage.removeItem(key)
}
边栏推荐
- mmdetection/mmdetection3d多机多卡训练
- Nacos集群搭建
- 2022年7月31日 暑假第三周总结
- C# Sqlite database construction and use skills
- 嵌入式开发:使用堆栈保护提高代码完整性
- Thrift IDL示例文件
- 面试官:可以谈谈乐观锁和悲观锁吗
- 自定义组件,并在组件中注入自定义组件实现多种场景的下的组件切换
- localhost,127.0.0.1,本机IP
- Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
猜你喜欢
要有遥不可及的梦想,也要有脚踏实地的本事
88. (the home of cesium) cesium polymerization figure
小程序笔记2
Learning to Explore - Setting the Foreground Color for Fonts
【图像分类】2021-DeiT
OpenInfra Days China 2022 | SelectDB to share with you the Apache Doris in Internet advertising business practices
网页端IM即时通讯开发:短轮询、长轮询、SSE、WebSocket
学习探索-网站中引入百度统计
软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
《机器学习理论到应用》电子书免费下载
随机推荐
小程序笔记2
Interval greedy (interval merge)
2018读书记
About the two architectures of ETL (ETL architecture and ELT architecture)
Introduction of three temperature measurement methods for PT100 platinum thermal resistance
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化柱状图、color参数指定柱状图的边框的色彩
数字化金融企业的产品体系长啥样?
《机器学习的随机矩阵方法》
Cron表达式
PT100铂热电阻三种测温方法介绍
小程序经典案例
并发编程原理学习-reentrantlock源码分析
【LeetCode Daily Question】——374. Guess the size of the number
面试官:可以谈谈乐观锁和悲观锁吗
《机器学习理论到应用》电子书免费下载
框架整合(二)- 使用Apache ShardingSphere实现数据分片
Learning to Explore - Setting the Foreground Color for Fonts
【日记】mysql基本操作
RecyclerView 缓存与复用机制
yarn detailed introductory tutorial