有的时候我们会用到刷新页面重新加载的功能但是VUE并没有提供,可通过一下方法进行设置达到页面重新加载

1.首先在app.vue里的router-view里加入v-if=“isRouterAlive”

  <router-view v-if="isRouterAlive"/>

2.在data中进行配置

provide(){
    return{
       reload:this.reload
    }
  },
  data(){
    return {
       isRouterAlive:true,
    }
  },
  methods:{
    reload(){
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true;
      })
    }
  }

3.在需要重新加载页面的页面中直接调用即可
需要在使用页面引入一下

inject:['reload'],

然后在需要的地方直接调用即可

 this.reload();
Logo

前往低代码交流专区

更多推荐