Vue實現頁面的局部刷新(router-view頁面刷新)

Vue實現頁面的局部刷新(router-view頁面刷新)

利用Vue裏面的provide+inject組合

  1. 首先需要修改App.vue。
<template>
  <!-- 公司管理 -->
  <div class="companyManage">
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>
export default {
  name: "companyManage",
  watch: {},
  provide() {
    return {
      reload:this.reload
    }
  },
  data() {
    return {
      isRouterAlive:true
    };
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick( () => {
        this.isRouterAlive = true;
      })
    }
  },
  mounted() {}
};
</script>

<style scoped>
.companyManage {
  width: 100%;
  height: 100%;
  position: relative;
  background: #fff;
}
</style>

在這裏插入圖片描述
2. 到需要刷新的頁面進行引用,使用inject導入引用reload,然後直接調用即可。
在這裏插入圖片描述

inject:["reload"],
this.reload();

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章