当前位置:网站首页>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)
}
边栏推荐
- Fork/Join框架
- R语言ggpubr包的ggline函数可视化折线图、设置add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、设置折线和数据点边框颜色
- 数字化金融企业的产品体系长啥样?
- 怎么面试程序员的?傲慢与无礼,就数他牛逼
- C# Sqlite database construction and use skills
- 最小区间覆盖
- 知乎高赞:拼多多和国家电网,选哪个?
- R语言时间序列数据算术运算:使用diff函数计算时间序列数据的逐次差分、使用时间序列之间的除法计算相对变化率(乘以100获得百分比)
- 设置表头颜色
- 框架整合(二)- 使用Apache ShardingSphere实现数据分片
猜你喜欢

小程序笔记2

基于层次分析法的“内卷”指数分析

SQL优化最全总结 - MySQL(2022最新版)

About the two architectures of ETL (ETL architecture and ELT architecture)

知乎高赞:拼多多和国家电网,选哪个?

网络靶场监控系统的安全加固纪实(1)—SSL/TLS对日志数据加密传输

JS兼容问题总结

下一代 AutoAI:从模型为中心,到数据为中心

PT100铂热电阻三种测温方法介绍

Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency
随机推荐
要有遥不可及的梦想,也要有脚踏实地的本事
About the two architectures of ETL (ETL architecture and ELT architecture)
嵌入式开发:使用堆栈保护提高代码完整性
js函数传参是按值传递还是按引用传递?
【无标题】
小程序笔记3
How to make JS code unbreakable
【日记】mysql基本操作
OpenInfra Days China 2022 | SelectDB to share with you the Apache Doris in Internet advertising business practices
Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency
化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
yarn详细入门教程
集群监控——Zabbix使用
R语言glm函数使用频数数据构建二分类logistic回归模型,分析的输入数据为频数数据(多个分类指标对应的阴性样本和阳性样本的频数数据)、weights参数指定频数值
区间贪心(区间合并)
Qt自动补全之QCompleter使用
小程序经典案例
启动项目(瑞吉外卖)
租房小程序登顶码云热门
88. (the home of cesium) cesium polymerization figure