vue路由守卫

路由守卫

//路由进来之时
  beforeRouteEnter(to, from, next) {
    console.log(this, 'beforeRouteEnter'); // undefined
    next(vm => {
      //因为当钩子执行前,组件实例还没被创建
      // vm 就是当前组件的实例相当于上面的 this,所以在 next 方法里你就可以把 vm 当 this 来用了。
      console.log(vm);//当前组件的实例
    });
  },

//路由离开前
 beforeRouteLeave(to, from, next) {
     next();
  },

//路由更新
//beforeRouterupdata(to, from, next){
     //对于一个带有动态参数的路径 /good/:id,在 /good/1 和 /good/2 之间跳转的时候,
    // 由于会渲染同样的good组件,因此组件实例会被复用。而这个钩子就会在这个情况下被调用。
}

获取参数

 this.$route.query.type;
 this.$route.params.type;
posted @ 2019-06-05 11:38  十年后2028  阅读(105)  评论(0编辑  收藏  举报