vue 钩子函数的初接触
vue-router的路由钩子函数: 第一种:全局钩子函数 。 router.beforeEach((to, from, next) => { console.log('beforeEach') //next() //如果要跳转的话,一定要写上next() //next(false) //取消了导航 next() //正常跳转,不写的话,不会跳转 }) router.afterEach((to, from) => { // 举例: 通过跳转后改变document.title if( to.meta.title ){ window.document.title = to.meta.title //每个路由下title }else{ window.document.title = '默认的title' } }) 第二种:针对单个路由钩子函数 beforeEnter(to, from, next){ console.log('beforeEnter') next() //正常跳转,不写的话,不会跳转 } 第三种:组件级钩子函数 beforeRouteEnter(to, from, next){ //