app.vue
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
</div>
</template>
<script>
export default {
provide() {
return {
reload: this.reload
}
},
data() {
return {
isRouterAlive: true
}
},
methods: {
reload() {
this.isRouterAlive = false
this.$nextTick(function() {
this.isRouterAlive = true
})
}
}
}
</script>
将要引用的页面 例如:home.vue
*注入*
inject: ['reload'],
*调用*
this.reload()
本文介绍了一种在Vue中实现路由页面重载的方法,通过在App.vue中控制router-view的显示状态,配合$nextTick实现页面刷新效果。适用于需要强制刷新页面数据场景。

被折叠的 条评论
为什么被折叠?



