路由钩子

129 阅读1分钟
  • 路由勾子

    • 全局路由勾子

      • router.beforeEach
      • router.afterEach
    • 路由所对应组件

      • beforeRouteEnter:进入前,当前组件实例化还没完成
        • next((_that)=>{_that代表的就是当前组件的this})
      • beforeRouteUpdate:更新前(路由改变了,但是路由所对应组件没有变)
        • this.$nextTick
      • beforeRouteLeave:离开时

    • 路由配制所对应勾子

      • {
        path,
        component,
        beforeEnter(to,from,next){
        
        }
        }
        
  • 执行先后:beforeEach===》beforeEnter===》beforeRouteEnter===》afterEach===》beforeRouteUpdate=》beforeRouteLeave

  • beforeDestroy

  • 从A组件(通过路由切换跳转)----B组件

    • A(beforeDestroy destroyed) B

      先执行B(beforeCreate(b)===>created(b)===>beforeMount(b)==>beforeDestroy(A)====>destroyed(A)====>mounted(b))