此方法使用的是v-if来控制router-view的显示或隐藏,v-if从false变为true时,vue会重新渲染router-view区域,所以当参数变化时,只需让v-if 从true => false => false,就能实现页面刷新;
问题描述
点击button发送请求,
路由不变,
需要刷新当前页面,
出现空白页。
版本提示:
此方法适用vue 2.20+版本,请先查看你的vue版本
1.首先,找到自己的route-view
APP.vue
2.使用 index.vue
刷新页面完全感觉不到刷新鸭,因为他真的不会出现空白闪烁的情况!
最后放上代码。
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
</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>