this.$router.go(-1)页面不刷新

this.$router.go(-1)页面不刷新,第1张

解决办法

使用this.$router.push
这种方法会刷新,但是前提是push的这个页面不是缓存的路由;

监听路由【不建议】

 @Watch('$route')
  private routeChange(){
    
  }

三、使用钩子函数beforeRouteEnter

Component.registerHooks([
  'beforeRouteEnter',
  'beforeRouteLeave',
  'beforeRouteUpdate', // for vue-router 2.2+
]);


private beforeRouteEnter(to:any,from:any,next:any) {
    console.log(this, 'beforeRouteEnter'); // undefined
    console.log(to, '组件独享守卫beforeRouteEnter第一个参数');
    console.log(from, '组件独享守卫beforeRouteEnter第二个参数');
    console.log(next, '组件独享守卫beforeRouteEnter第三个参数');
    next();
  }

四、因为你的是缓存页面就可以使用activated
vue对象存活的情况下,进入当前存在activated()函数的页面时,一进入页面就触发;可用于初始化页面数据等

 private activated(){
    this.getBranchList();
    this.getVersionList();
  }

参考https://blog.csdn.net/Nalaluky/article/details/84201445

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/994776.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存