美文网首页
vue刷新页面方式

vue刷新页面方式

作者: xsmile21 | 来源:发表于2022-04-06 15:29 被阅读0次

1、传统方法
window.location.reload();
2、router方法
this.$router.go(0);
前面两种方式是强制刷新页面,会有短暂的闪烁。。。
优化如下:
App.vue

export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isRouterAlive: true
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function() {
        this.isRouterAlive = true;
      })
    }
  }
}

然后在需要用到的地方调用即可

inject: ['reload']
this.reload();

相关文章

网友评论

      本文标题:vue刷新页面方式

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