vue keep-alive 缓存问题最终解决方案

解决方案,我使用了activated和 beforeRouteLeave两个生命周期配合使用

注意:要先把数据恢复默认值

// 缓存处理
  activated(){
    if(this.isKeepAlive){
        this.seq_uuid = ''
        this.adcode = '' 
        this.amount = ''
        this.name = ''
        this.term = {}    
        this.applyField = [] 
        this.seq_uuid = this.$route.query.seq_uuid;
        this.adcode = this.$route.query.adcode;
        this.type_show = this.$route.query.type_show;
        this.getQueryApplyField(this.$route.query.seq_uuid);
    }
  },
  // 缓存处理
  beforeRouteLeave (to, from, next) {
    if(to.meta.isProtocol && to.name == 'loginProtocolList'){
        this.isKeepAlive = false;      
    }
    if(to.name == 'LoanInfo'){
      this.isKeepAlive = true;      
    }
    if(to.name == 'SubmitSuccess'){
      this.isKeepAlive = true;      
    }
    next();
  },

缓存的页面 created 会执行只有一次,activated每次都会执行 , created 里面做 第一次 isFirstEnter = true(由于页面被缓存,所以一直生效),之后再activated 里面做判断 只有 “不是返回回来的” 和 “第一次进来的” 就刷新数据, 并且要在下面 都设为false, 以免缓存各标识不对,在进入 “列表页” 时,通过router钩子函数 beforeRouteEnter做判断,详情页过来的设 isBack 为true,即不刷新页面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值