vue中使用jwt-decode解析token的方法
安裝:
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獲取需要的數(shù)據(jù)
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、這樣就拿到了,然后在需要使用的時候直接使用就行
//獲取解析的數(shù)據(jù) localStorage.getItem("decode");
到此這篇關(guān)于vue中使用jwt-decode解析token的文章就介紹到這了,更多相關(guān)vue解析token內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue結(jié)合Echarts實現(xiàn)點擊高亮效果的示例
下面小編就為大家分享一篇vue結(jié)合Echarts實現(xiàn)點擊高亮效果的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03vue $set 實現(xiàn)給數(shù)組集合對象賦值
這篇文章主要介紹了vue $set 實現(xiàn)給數(shù)組集合對象賦值方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07vue3?中的toRef函數(shù)和toRefs函數(shù)的基本使用
這篇文章主要介紹了vue3?toRef函數(shù)和toRefs函數(shù),文中介紹了ref和toRef的區(qū)別,ref本質(zhì)是拷貝,修改響應(yīng)式數(shù)據(jù)不會影響原始數(shù)據(jù),toRef的本質(zhì)是引用關(guān)系,修改響應(yīng)式數(shù)據(jù)會影響原始數(shù)據(jù),需要的朋友可以參考下2022-11-11vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作
這篇文章主要介紹了vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07