首页 > 其他 > 详细

vue组件重新加载(刷新)

时间:2018-06-13 13:01:17      阅读:444      评论:0      收藏:0      [点我收藏+]

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

vue组件重新加载(刷新)

原文:https://www.cnblogs.com/s313139232/p/9176820.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!