如何在angular 9中解码令牌
我想解码一个令牌。 但我要提出警告如何在angular 9中解码令牌,angular,typescript,Angular,Typescript,我想解码一个令牌。 但我要提出警告 npm install jwt-decode --save 组件1.ts: import * as jwt_decode from 'jwt-decode'; . . . console.log("Yes"); localStorage.setItem('token', res.token); this.flagProgressBar = false; console.log
npm install jwt-decode --save
组件1.ts:
import * as jwt_decode from 'jwt-decode';
.
.
.
console.log("Yes");
localStorage.setItem('token', res.token);
this.flagProgressBar = false;
console.log('res.token: ');
console.log(res.token);
console.log('localStorage token:');
console.log(localStorage.getItem('token'));
const tokene = res.token;
const decoded = jwt_decode(tokene);
console.log(tokene);
console.log(decoded);
控制台:
Yes
res.token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvnQuY29tL3dzLzIwMgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJGdWxsQWRtaW4iLCJleHAiOjE2MDM5MjEzNzMsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0OjQ0MzU0In0.-e7cYAgQQVTcHlPrw1sWn6IsjhVPfjlItx9XGIn3S9w
localStorage token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy5WNybNvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJGdWxsQWRtaW4iLCJleHAiOjE2MDM5MjEzNzMsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0OjQ0MzU0In0.-e7cYAgQQVTcHlPrw1sWn6IsjhVPfjlItx9XGIn3S9w
ERROR TypeError: jwt_decode__WEBPACK_IMPORTED_MODULE_2__ is not a function
at SafeSubscriber.Service.postDataLogin.subscribe.flagProgressBar [as _next]
是否可以说出我的问题出在哪里?获取jwt解码工作的快速示例应用步骤:
jwt_解码导入错误尝试此
从“jwt解码”导入jwt_解码代码>这适用于旧版本
import * as jwt_decode from "jwt-decode";
对于较新版本(3及以上版本):
你能展示一下你是如何导入这个jwt\u decode
功能的吗?我从“jwt decode”编辑了问题import jwt\u decode;将导入*替换为“jwt解码”中的jwt_解码;
import * as jwt_decode from "jwt-decode";
import jwt_decode from 'jwt-decode';