vue2-使用watch监听路由的变化

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

 

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

 

watch: {
  $route: {
    handler: function(val, oldVal){
      console.log(val);
    },
    // 深度观察监听
    deep: true
  }
}
posted @ 2024-05-07 08:55  相遇就是有缘  阅读(138)  评论(0)    收藏  举报