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