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周期之后。