vue實現某個頁面強制刷新router-view


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. 到需要刷新的頁面進行引用,使用inject導入引用reload,然后直接調用即可

<template>
  <div></div>
</template>

<script>
export default {
  inject: ['reload'],
  data() {
    return {},
  },
  created() {
    this.reload();
  },
  methods: {},
}
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM