梦幻

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

to  准备跳转到哪个页面

from 从哪个页面中离开

next  函数

全局守卫

router.beforeEach((to,from,next) => {
   if(to.path == '/login' || to.path == '/register'){
    next(); }else{
    alert('先登录')
    next('/login') } })

组件守卫

data () {
  return{
    name: 'zuo'
  }
}
beforeRouteEnter:(to, from, next) => {
  next(vm => {
    alert("123" + name)
  })
}
beforeRouteEnter:(to, from, next) => {
  if(confirm("确认离开吗")){
    next();
  }else{
    next(false)
  }
}

 

posted on 2019-03-15 13:46  ⅠⅡ  阅读(284)  评论(0编辑  收藏  举报