当前位置:网站首页>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)
}
边栏推荐
猜你喜欢

框架整合(二)- 使用Apache ShardingSphere实现数据分片

NLP未来,路在何方?从学术前沿和业界热点谈起

如何模拟后台API调用场景,很细!

CF86D Powerful array

Create Sentinel high-availability cluster current limiting middleware from -99

小程序笔记1

About the two architectures of ETL (ETL architecture and ELT architecture)
![[Web Automation Test] Quick Start with Playwright, 5 minutes to get started](/img/68/36dd8ef4a4073f03d5e5dad91be20d.png)
[Web Automation Test] Quick Start with Playwright, 5 minutes to get started

yarn详细入门教程

.NET云原生应用发展论坛--8月7日邀你一起云上探索
随机推荐
Cholesterol-PEG-DBCO,CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔科研试剂
怎么招聘程序员
pyhon爬虫之爬取图片(亲测可用)
Introduction of three temperature measurement methods for PT100 platinum thermal resistance
要有遥不可及的梦想,也要有脚踏实地的本事
身为程序员的我们如何卷死别人?破局重生。
SRM Supplier Collaborative Management System Function Introduction
How to recruit programmers
LVS+Keepalived群集
餐饮供应链管理系统
Boosting之GBDT原理
codeforces每日5题(均1600)-第二十八天
学习探索-网站中引入百度统计
网页端IM即时通讯开发:短轮询、长轮询、SSE、WebSocket
区间贪心(区间合并)
SRM供应商协同管理系统功能介绍
R语言glm函数使用频数数据构建二分类logistic回归模型,分析的输入数据为频数数据(多个分类指标对应的阴性样本和阳性样本的频数数据)、weights参数指定频数值
【日记】UPNP功能会允许自动给光猫追加端口映射
R语言使用ggpubr包的ggsummarystats函数可视化柱状图(通过ggfunc参数设置)、在可视化图像的下方添加描述性统计结果表格、palette参数配置柱状图及统计数据的颜色
从-99打造Sentinel高可用集群限流中间件