刷新当前页面 (Vue)

1.首先在APP.vue里面,写入刷新方法,路由初始状态是显示的

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

<router-view v-if=“isRouterAlive”></router-view> 在isRouterAlive 为true的地方 使用刷新 ,然后在其他组件或者页面中调用相应方法就行

子级调用刷新方法

  1. 先映入 inject: [‘reload’],
    在这里插入图片描述
  2. 调用函数 this.reload() 即可

猜你喜欢

转载自blog.csdn.net/weixin_41854372/article/details/109111634