vue中使用jwt-decode解析token的方法
作者:~疆 时间:2023-07-02 17:03:24
安装:
cnpm i -S jwt-decode
引入:
import jwt_decode from "jwt-decode";
使用:
import jwt_decode from "jwt-decode";
console.log("token:", token)
console.log("解析后的token:", jwt_decode(token))
补充:vue通过jwt-decode解析token获取需要的数据
1、安装jwt-decode插件
npm install jwt-decode --save
//慢的话可以cnpm
cnpm install jwt-decode --save
2、在页面引入安装的插件
这里我是在vuex中引入的,因为我在登录拿到token后,我就需要解析token,然后将信息保存起来
import jwt_decode from "jwt-decode";
3、使用
// 解析获取token
//data.normal_login_token为请求到的token
const decode = jwt_decode(data.normal_login_token).accountId; // 解析
// 保存accoundId
localStorage.setItem("decode", decode);
4、这样就拿到了,然后在需要使用的时候直接使用就行
//获取解析的数据
localStorage.getItem("decode");
来源:https://blog.csdn.net/qq_40323256/article/details/125297172
标签:vue,jwt,decode,token
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解析pip安装第三方库但PyCharm中却无法识别的问题及PyCharm安装第三方库的方法教程
2023-05-17 04:25:43
![](https://img.aspxhome.com/file/2023/1/121731_0s.jpg)
详解Numpy数组转置的三种方法T、transpose、swapaxes
2023-01-14 21:42:13
![](https://img.aspxhome.com/file/2023/7/77667_0s.png)
基于Python实现简单的定时器详解
2021-04-12 01:21:28
![](https://img.aspxhome.com/file/2023/5/95895_0s.png)
通过不同的CSS设计字体大小来提高用户体验
2008-12-10 19:17:00
Python数据可视化图实现过程详解
2022-08-30 19:24:17
![](https://img.aspxhome.com/file/2023/7/81557_0s.jpg)
Sql Server 分组统计并合计总数及WITH ROLLUP应用
2024-01-25 03:55:31
Python实现爬取知乎神回复简单爬虫代码分享
2023-03-23 19:00:10
![](https://img.aspxhome.com/file/2023/8/81778_0s.jpg)
深入理解JS中的substr和substring
2024-04-16 10:29:24
mysql表的性能提升的相关问题
2010-03-03 16:31:00
深入理解Python3 内置函数大全
2022-06-27 22:11:36
![](https://img.aspxhome.com/file/2023/1/87591_0s.png)
python 基于 tkinter 做个学生版的计算器
2022-07-30 18:43:54
![](https://img.aspxhome.com/file/2023/1/131351_0s.jpg)
最具创意的广告牌全集
2007-09-21 19:54:00
![](https://img.aspxhome.com/file/UploadPic/20079/21/200792120756728s.jpg)
MySQL 8.0.19支持输入3次错误密码锁定账户功能(例子)
2024-01-28 04:48:00
利用xmlhttp和adodb.stream加缓存技术下载远程Web文
2009-04-23 18:33:00
python版微信跳一跳游戏辅助
2021-08-16 09:03:19
![](https://img.aspxhome.com/file/2023/8/135128_0s.jpg)
python如何支持并发方法详解
2021-05-29 16:50:17
ajax Google PageRank3(PR值)查询源代码
2007-11-04 13:31:00
![](https://img.aspxhome.com/file/UploadPic/200711/4/2007114142753675s.gif)
Django+Uwsgi+Nginx如何实现生产环境部署
2023-02-08 00:48:48
![](https://img.aspxhome.com/file/2023/3/70873_0s.png)
Python 中的pass语句语法详析
2023-02-11 03:17:44
MySQL两种临时表的用法详解
2024-01-26 20:37:46