vue vue-router是否已登录 路由验证
作者:
fancheur | 来源:发表于
2020-06-23 15:02 被阅读0次
main.js
router.beforeEach((to, from, next) => {
let isLogin = localStorage.getItem('userInfo') //登录时存的数据
if (to.matched.some(record => record.meta.requireLogin)) { //路由页面是否有meta值
if ( to.name !== 'login' && !isLogin ) {
next({ path: '/' })
} else {
next()
}
} else {
next()
}
})
router/index.js
//在路由页面 加meta 判断此页面是否需要登陆后才可以进入
{
path: '/record',
name: 'record',
component: record,
meta: { requireLogin: true }
}
本文标题:vue vue-router是否已登录 路由验证
本文链接:https://www.haomeiwen.com/subject/ftrhfktx.html
网友评论