参考 : vue项目刷新当前页面的三种方法_Linux小百科的博客-CSDN博客_vue刷新页面
1.[src/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.引入
<template>
</template>
<script>
export default {
inject:['reload'],
name:"test",
data(){
return{
}
},
methods:{
refresh(){
this.reload()
}
}
}
</script>
声明 inject:['reload'] 即可使用 this.reload() 刷新
这篇博客介绍了在Vue项目中刷新当前页面的两种方法。第一种是在`App.vue`中利用`v-if`和`$nextTick`来实现页面的伪刷新;第二种是通过在组件中注入`reload`方法来调用刷新。这种方法对于需要刷新特定页面场景非常有用。

1404

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



