VUE 页面刷新推荐方式

在APP.vue中编写代码

<template>
<div id="app">
<router-view v-if="isRouteAlive" />
</div>
</template>

<script>
export default {
name: 'App',
provide() {
return {
reload: this.reload
}
},
data() {
return {
isRouteAlive: true
}
},
methods: {
reload() {
this.isRouteAlive = false
this.$nextTick(() => {
this.isRouteAlive = true
})
}
}
}
</script>
然后在需要刷新的页面引入即可,代码如下:
export default {
  inject: ['reload']
}

通过 this.reload()调用即可

本人测试使用没有问题 不闪屏 不会一瞬间白屏 体验效果不错
posted @ 2021-04-07 10:48  xcdSir  阅读(87)  评论(0编辑  收藏  举报