vue 导航守卫

全局前置守卫



简单例子
配置index.js信息

//模拟登录
const flag=true;
//全局前置守卫,起到拦截作用
router.beforeEach((to,from,next)=>{
      if(flag){
        //继续执行正常跳转
        if(to.name=='Login') next('/')
        else next()
      }
      else {
        //跳转到登录页面
        if(to.name=='Login') next()
        else next('/login')
      }
})

路由独享的守卫

组件内的守卫


posted @ 2021-07-26 17:23  一个经常掉线的人  阅读(34)  评论(0编辑  收藏  举报