原生js页面刷新:
window.location.reload()
vue中页面刷新:
this.$router.go(0)
以上两种刷新方法会出现闪的效果,相对来讲,这对用户的体验不是很好,那有页面刷新既不闪,还能实现页面刷新的效果呢?有,如下:
1.App.vue:
<template>
<div id="app">
<router-view v-if="isRouterAlive"/>
</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>
2.在需要的组件中: