第一种办法:
监听后进入页面会执行两次,还有其他页面也会执行,第一次不执行
加入immediate: true
第一次会调用,只调用一次
watch: {
'$route':{
handler(to, from) {
if(to.path==='/pages/personCenter/media/setRecipients'&&!to.query==''){
this.getData()
}
},
immediate: true
}
}
第二种办法:
<router-view :key="key" ref="routerView"/>
//绑定一个随机key 利用计算属性
computed:{
key(){
return this.$route.path + Math.random();
}
},
第三种办法:
//加v-if 销毁重组
<router-view v-if='' ref="routerView"/>
网友评论