vueRouter学习笔记

1. 守护函数,也为守护钩子,是管理路由的生命周期中各个阶段注入的自定义函数。

全局前置和后置守护分别是:beforeEach和 afterEach、常用:

router.beforeEach((to, from, next)=>{
   loading.show() // 用户体验
   next()             // 只能调用一次。 
})
router.afterEach((to, from) =>{
  loading.hide()
})

2、区别this.$route和this.$router,在vue实例中都可以访问。this.$route是指当前的路由信息,

     包括:path、query、params、name、meta、 hash、 fullhash、matched、

     应用场景:守护函数中参数、路径观察中用到。

     this.$router 全局路由配置信息。负责守护、跳转等。

posted @ 2021-06-09 09:33  anthonyliu  阅读(52)  评论(0编辑  收藏  举报