实现页面刷新不闪烁,同 this.$router.push()

1.app.vue

<template>
  <div id="app">
    <router-view v-if="isRouterAlive" /> 
  </div>
</template>

<script>
    export default {
        name: "App",
        //解决跳转到当前页面不刷新问题
        provide() {
          return {
            reload: this.reload,
          };
        },
        data() {
          return {
            isRouterAlive: true,
          }
        },
        methods:{
          reload() {
              this.isRouterAlive = false;
              this.$nextTick(() => {
                this.isRouterAlive = true;
              });
          },
        }
    }
</script>

2.调用刷新的页面

export default {
    inject: ["reload"],
    methods:{
        changeLanguage(item) {
             var that = this;
             // this.pageLoading();
             that.curLang = item.name;
             //修改全局语言状态
             this.$i18n.locale = item.value;
             localStorage.setItem("language", item.value);
             this.reload()                   
        }
    }
}

度vApud
11 声望0 粉丝

« 上一篇
表单正则
下一篇 »
Webpack配置