美文网首页
vue路由跳转权限拦截判断

vue路由跳转权限拦截判断

作者: 嗨姑娘_大个子 | 来源:发表于2018-10-23 19:31 被阅读0次

参考:https://www.cnblogs.com/WQLong/p/8135553.html

1. 全局钩子函数:
  • beforeEach函数有三个参数:
  1. to:router即将进入的路由对象
  2. from:当前导航即将离开的路由
  3. next:Function,进行管道中的一个钩子,如果执行完了,则导航的状态就是 confirmed (确认的);否则为false,终止导航。
  • afterEach函数不用传next( )函数。
Vue.beforeEach(function(to,form,next){})     /*在跳转之前执行*/
Vue.afterEach(function(to,form))     /*在跳转之后判断*/
2. 路由函数:
const router = new VueRouter({
  routes: [ {
      path: '/login',
      component: Login,
      beforeEnter: (to, from, next) => {
        // ...
      },
      beforeLeave: (to, from, next) => {
        // ...
      }
    }
  ]
})

相关文章

网友评论

      本文标题:vue路由跳转权限拦截判断

      本文链接:https://www.haomeiwen.com/subject/aizazftx.html