vue 回退 不刷新 缓存问题 从A页跳到B页,缓存A页,当B再次返回A时,页面不刷新

    //在index.js中
        {
        path: '/SearchContent',
        name: 'SearchContent',
        component: SearchContent,
        meta: {
          keepAlive: false,//此组件不需要被缓存
          isBack:false 
        }
      },
      {
        path: '/Shop',
        name: 'Shop',
        component: Shop,
        meta: {
          keepAlive: false, 
          isBack:false//判断上一个页面
        }
      },

//在searchContent中
beforeRouteEnter(to, from, next) {
         // 设置下一个路由的 meta
         if(from.name == 'Shop'){
             to.meta.isBack = true;
             to.meta.keepAlive = true;
         } // 让 A 缓存,即不刷新
        next();
    },
    components:{
        "app-brands":Brand
    },
//注意activated只能在keep-alive组件中调用
     activated() {
  if(!this.$route.meta.isBack){
    
    // 如果isBack是false,表明需要获取新数据,否则就不再请求,直接使用缓存的数据
    this.getData();
    this.getTree();
  }
  // 恢复成默认的false,避免isBack一直是true,导致下次无法获取数据
  this.$route.meta.isBack=false
 
},
//在进入页面时调用接口请求数据,当数据请求完成,第二次进入页面时,就会执行activated函数
 mounted(){
        this.getData()
        this.getTree()
    },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值