监听路由的变化

126 阅读1分钟

vue watch方法

watch:{
 $route(tofrom){
 //我们这里可以监听路由的变化,可以在这里调用函数
}
watch: {
   $route: {
     handler:  (val, oldVal)=>{
       console.log(val);
     },
     // 深度观察监听
     deep:  true
   }
}
watch: {
   '$route' : 'getBrowerParams'
},
methods: {
   getBrowerParams{
     console.log( this .$route.path);
   }
}

我们可以通过监听路由的变化,用来调用某些函数