vue路由跳转权限拦截判断

2018-10-23  本文已影响0人  嗨姑娘_大个子

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

1. 全局钩子函数:
  1. to:router即将进入的路由对象
  2. from:当前导航即将离开的路由
  3. next:Function,进行管道中的一个钩子,如果执行完了,则导航的状态就是 confirmed (确认的);否则为false,终止导航。
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) => {
        // ...
      }
    }
  ]
})
上一篇 下一篇

猜你喜欢

热点阅读