Vue 页面局部刷新

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue 页面局部刷新

小城听风雨   2022-05-23 我要评论

利用Vue里面的provide+inject组合

首先需要修改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();

在这里插入图片描述

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们