关于javascript:Vue无感刷新页面

实现页面刷新不闪动,同 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()                   
        }
    }
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理