vue里面watch监听当前路由信息
开发中有这么个小需求,就是需要获取当前页面的路由信息,然后做相关的操作,这里使用watch对当前路由进行监听,代码如下:
watch:{
'$route':function(){
console.log('watch里面',this.$route.name);
if(this.$route.name === 'home'){
this.isHomeRouter = true;
}else{
this.isHomeRouter = false;
}
console.log(this.isHomeRouter,'监听路由变化')
}
},
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/69d93b8cdfdf832efd0adafedb021ef2.png)