发表于: 2020-04-01 21:06:15

1 1587



今天完成的事情:

1.推进任务


明天计划的事情:

1.推进任务



遇到的问题和收获:

比如直接打开这个界面,不会被登录验证拦截。从这个界面跳转其它界面时,才会触发登录验证


//验证是否登录,未登录则跳转到登录页面
// 在每次路由切换的时候调用这个钩子方法会接收三个参数:tofromnext
router.beforeEach((to, from, next) => {
   console.log(to);
   if (to.matched.some(res=>res.meta.needLogin)) {
       if (JSON.parse(window.sessionStorage.getItem('sid'))) {
           console.log('有登录名')
           next()
       } else {
           next({
               path:'/login',
               query:{
                   redirect:to.fullPath
               }
           });
       }
   } else {
       next()
   }


需要登录的组件

{
   path: '/home',
   component: ArticleMain,
   redirect: '/home/welcome',
   meta: {
       needLogin: true
   },//配置meta,进入页面前判断是否需要登录


这里就不知道应该怎么判断了



返回列表 返回列表
评论

    分享到