Vue实现页面的局部刷新

1. 首先需要修改App.vue 

App.vue

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

2. 到需要刷新的页面进行引用,使用inject导入引用reload,然后直接调用即可


版权声明:本文为qq_40323256原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。