vue里面watch监听当前路由信息
开发中有这么个小需求,就是重复路由不触发生命周期
监听路由触发初始化方法
watch: {
'$route': function () {
this.init()
}
},
或者是监听路由变化 做出后续处理
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,'监听路由变化')
}
},