当前位置:网站首页>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)
}
边栏推荐
- yarn详细入门教程
- LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order
- R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值、使用%>%符号将多个函数串起来
- 两个对象相同数据赋值
- Nacos集群搭建
- Thrift安装配置
- 2022年7月31日 暑假第三周总结
- Introduction of three temperature measurement methods for PT100 platinum thermal resistance
- R语言计算时间序列数据的逐次差分(successive differences):使用diff函数计算时间序列数据的逐次差分值
- 【日记】nodejs构建API框架以及RESTful API 和 JSON-RPC的取舍
猜你喜欢

化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升

What does the product system of a digital financial enterprise look like?

微信jsApi调用失效的相关问题

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

Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency

Boost library study notes (1) Installation and configuration
The second step through MySQL in four steps: MySQL index learning

学习探索-网站中引入百度统计

字节二面被问到mysql事务与锁问题,我蚌埠住了

【技术积累】JS事件循环,Promise,async/await的运行顺序
随机推荐
怎么面试程序员的?傲慢与无礼,就数他牛逼
使用bash语句,清空aaa文件夹下的所有文件
R语言缺失时间序列的填充及合并:补齐时间序列数据中所有缺失的时间索引、使用merge函数合并日期补齐之后的时间序列数据和另外一个时间序列数据(补齐左侧数据)
框架整合(二)- 使用Apache ShardingSphere实现数据分片
并发编程原理学习-reentrantlock源码分析
Interval greedy (interval merge)
从-99打造Sentinel高可用集群限流中间件
公司自用的国产API管理神器
The prefix and discretization
C# Sqlite database construction and use skills
消灭异步回调,还得是async-await
darknet source code reading notes-02-list.h and lish.c
Speech Recognition Learning Resources
(一)、线性表的顺序存储结构链式存储结构
C. LIS or Reverse LIS?
RecyclerView 缓存与复用机制
SRM供应商协同管理系统功能介绍
小程序经典案例
Matlab画图1
LeetCode 899. Ordered Queues