最新亚洲精品福利在线,欧美一区二区三区大片,久久91无码一区二区三区,色哟哟免费观看视频入口,美女裸露双奶头屁股无裸体

watch監(jiān)聽(tīng)路由變化詳解

時(shí)間:2021-09-14 11:20:17 類(lèi)型:vue
字號(hào):    

  一、watch監(jiān)聽(tīng)路由的方法

  通過(guò)watch監(jiān)聽(tīng),當(dāng)路由發(fā)生變化的時(shí)候執(zhí)行。

  方法一:

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

  方法二:

watch: {
   $route: {
     handler:  function (val, oldVal){
       console.log(val);
     },
     // 深度觀察監(jiān)聽(tīng)
     deep:  true
   }
},

  方法三:

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


<