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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM