首页 > 技术文章 > vue如何刷新当前页

lxn2 2020-06-11 14:45 原文

项目中会有需求刷新当前整个页面,用路由直接刷新的话会有一个白色闪屏出现,怎么解决这个问题呢?

1、首先 我们需要创建一个空白页面

<template></template>
<script>
export default {
  name: 'reload',
  props: {},
  beforeCreate() {
      const { query } = this.$route;
      const { path } = query;
      this.$router.replace({
          path: path
      });
  },
  render(h) {
    return h();
  }
}
</script>

2、在需要用到刷新的页面直接调用

const { fullPath } = this.$route;
this.$router.replace({
    path: "/redirect",
    query: { path: fullPath }
});

注:如果还有其他解决方案 欢迎留言补充交流哦~

推荐阅读