beforeRouteEnter(to,from, next){
console.log(this) //undefined
next(vm => {
console.log(vm)})
}
1 if (token) { 2 if (router.options.isAdd) { //判断是否已经添加动态路由 3 next(); 4 } else { 5 getMenuData(to, next); 6 } 7 next() //这里的next()一定不能忘! 8 } else { 9 if (to.path === '/login') { // 如果是登录页面的话,直接next() 10 next(); 11 } else { 12 next({ 13 path: '/login' 14 }); 15 } 16 }
next()里的内容执行时机在组件mounted周期之后。