首页 > 技术文章 > vue 页面刷新

miny-simp 2018-11-15 10:32 原文

app.vue

<template>
  <div id="app">
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>
<script>
export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data () {
    return {
      isRouterAlive: true
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true;
      })
    }
  }
  
}
</script>

需要刷新的页面(lscz.vue)中注册 reload ,调用reload() 方法,

export default {
  components: {
    "v-lsczLeft": lsczLeft
  },
  inject: ['reload'],  //注入reload方法
  data() {
    return {
    };
  },
  methods: {
    gdSubmit() {
       this.teload();  //刷新
    }
  }
}

 

推荐阅读