美文网首页前端
路由跳转,回退再次进入,生命周期不调用问题

路由跳转,回退再次进入,生命周期不调用问题

作者: 一个健康马 | 来源:发表于2020-05-14 16:15 被阅读0次

第一种办法:
监听后进入页面会执行两次,还有其他页面也会执行,第一次不执行
加入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"/>

相关文章

网友评论

    本文标题:路由跳转,回退再次进入,生命周期不调用问题

    本文链接:https://www.haomeiwen.com/subject/hrotohtx.html