关于javascript:Vue无感刷新页面

18次阅读

共计 568 个字符,预计需要花费 2 分钟才能阅读完成。

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

正文完
 0