vue监听路由变化

1、

watch:{
  $route(to,from){
    console.log(to.path);
  }
},

2、

watch: {
  $route: {
    handler: function(val, oldVal){
      console.log(val);
    },
    // 深度观察监听
    deep: true
  }
},

3、

watch: {
  '$route':'getPath'
},
methods: {
  getPath(){
    console.log(this.$route.path);
  }
}

 

posted @ 2021-07-16 08:45  (⊙o⊙)买噶  阅读(246)  评论(0编辑  收藏  举报