vue如何刷新当前页

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

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 }
});

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

原文地址:https://www.cnblogs.com/lxn2/p/13093180.html