美文网首页
vue刷新当前页面,重载页面数据

vue刷新当前页面,重载页面数据

作者: Hassd | 来源:发表于2018-09-20 23:37 被阅读0次

根组件APP.vue里面,写入刷新方法,路由初始状态是显示的

<template>

  <div id="app">

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

  </div>

</template>

<script>

export default {

  name: 'App',

  provide (){

    return {

      reload:this.reload

    }

  },

  data(){

    return {

      isRouterAlive:true

    }

  },

  methods:{

    reload (){

      this.isRouterAlive = false

      this.$nextTick(function(){

          this.isRouterAlive = true

      })

    }

  }

}

</script>

然后在子组件里面进行引用

inject:['reload']

在执行完相应的操作,后调用reload方法

this.reload()

相关文章