vue 設(shè)置路由的登錄權(quán)限的方法
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-27 22:12:01
vue 設(shè)置路由的登錄權(quán)限的方法
vue 設(shè)置路由的登錄權(quán)限的方法:index.js 將需要登錄權(quán)限的路由設(shè)置meta屬性 meta:{requireAuth:true}, main.js 在main.js內(nèi)直接寫對路由的驗證 router.beforeEach((to, from, next) => { if (to.matched.some(record => record.
導(dǎo)讀vue 設(shè)置路由的登錄權(quán)限的方法:index.js 將需要登錄權(quán)限的路由設(shè)置meta屬性 meta:{requireAuth:true}, main.js 在main.js內(nèi)直接寫對路由的驗證 router.beforeEach((to, from, next) => { if (to.matched.some(record => record.
index.js
將需要登錄權(quán)限的路由設(shè)置meta屬性

main.js
在main.js內(nèi)直接寫對路由的驗證
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requireAuth)){ // 判斷該路由是否需要登錄權(quán)限
if (sessionStorage.getItem("access_token")) { // 判斷當(dāng)前的token是否存在
next();
}
else {
next({
path: '/manage',
query: {redirect: to.fullPath} // 將跳轉(zhuǎn)的路由path作為參數(shù),登錄成功后跳轉(zhuǎn)到該路由
})
}
}
else {
next();
}
});
總結(jié)
以上所述是小編給大家介紹的vue 設(shè)置路由的登錄權(quán)限的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
vue 設(shè)置路由的登錄權(quán)限的方法
vue 設(shè)置路由的登錄權(quán)限的方法:index.js 將需要登錄權(quán)限的路由設(shè)置meta屬性 meta:{requireAuth:true}, main.js 在main.js內(nèi)直接寫對路由的驗證 router.beforeEach((to, from, next) => { if (to.matched.some(record => record.