vue无痕刷新

父组件

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

子组件

  props: {},
  inject:['reload'],
  data() {
    return {}
   }    

使用
this.reload();

猜你喜欢

转载自www.cnblogs.com/-roc/p/12107008.html