vue路由钩子
2019-04-25 本文已影响2人
一条小团团ovo的就很棒
-
路由钩子
1.全局钩子
2.某个路由独享钩子
3.组件内钩子
-
全局钩子
beforeEach(全局前置守卫)、afterEach(全局后置钩子)
Router.beforeEach((to,from,next)=>{
......
})
Router.afterEach((to,from,next)=>{
......
})
-
某个路由独享钩子
- beforeEnter
- beforeLeave
{
path:"/home",
component:resolve=>require(["../components/home.vue"],resolve),
beforeEnter:(to,from,next)=>{
......
},
beforeLeave:(to,from,next)=>{
......
}
}
-
组件内钩子
1.beforeRouteLeave
2.beforeRouteEnter
3.beforeRouteUpdate
methods:{
beforeRouteLeave(to,from,next){
.......
}
}