vue路由钩子函数

版权声明:三和小钢炮 https://blog.csdn.net/fwx426328/article/details/83994888

一、全局钩子

router.beforeEach((to, from, next) => {
  console.log('beforeEach');
});

router.afterEach((to, from) => {
  console.log('beforeEach');
});

二、单个路由钩子

const router = new VueRouter({
  routes: [{
    path: '/index',
    component: index,
    beforeEnter(to, from, next) {},
    beforeLeave(to, from, next) {}
  }]
});

三、组件钩子

export default {
  beforeRouteLeave(to, from, next) {},
  beforeRouteEnter(to, from, next) {},
  beforeRouteUpdate(to, from, next) {}
};

猜你喜欢

转载自blog.csdn.net/fwx426328/article/details/83994888