在路由控件多添加一个属性(requireAuth:false),判断是否需要用户登录 1.在main.js中(也可以在其它页面定义)// 判断是否登录状态to:当前路由的参数,next执行这个跳转路由router.beforeEach(func
1.在main.js中(也可以在其它页面定义)
// 判断是否登录状态to:当前路由的参数,next执行这个跳转路由
router.beforeEach(function (to, from, next) {
if (to.meta.requireAuth) {
// var that = this
next()
if (sessionStorage.userName) {
console.log('存在用户,一般不需要执行什么')
} else {
fadefun.pupopFade('请先登录您的账号!', 300)
setTimeout(function () {
//跳转到登录页面
next({
name: 'login'
})
}, 1400)
}
} else {
// console.log('false')
//跳转路由(可以直接进入)
next()
}
})
export default router
2.在index.js(路由控制器页面)
routes: [
...
{
path: '/page/personal',
name: 'personal',
meta: {
requreAuth: true
},
component: personal
}
]
