vue组件重新加载(刷新)

vue组件重新加载(刷新)

第一种方法:利用v-if控制router-view,在根组件APP.vue中实现一个刷新方法

<template>
<router-view v-if="isRouterAlive"/>
</template>
<script>
export default {
 data () {
   return {
     isRouterAlive: true
   }
 },
 methods: {
   reload () {
     this.isRouterAlive = false
     this.$nextTick(() => (this.isRouterAlive = true))
   }   
 }
}
</script>

然后其它任何想刷新自己的路由页面,都可以这样:
this.reload()

 这种方法可以实现任意组件的刷新。

第二种方法:路由替换

 // replace another route (with different component or a dead route) at first
// 先进入一个空路由
vm.$router.replace({
  path: '/_empty',
})
//then replace your route (with same component)
vm.$router.replace({
  path: '/student/report',
  query: {
    'paperId':paperId
  }
})

转载自:https://blog.csdn.net/weixin_40054326/article/details/79384433

猜你喜欢

转载自www.cnblogs.com/s313139232/p/9176820.html