1.在App.vue
,声明reload
方法,控制router-view
的显示或隐藏,从而控制页面的再次加载。
<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>
在需要用到刷新的页面。在页面注入App.vue
组件提供(provide
)的 reload
依赖,在逻辑完成之后(删除或添加...),直接this.reload()
调用,即可刷新当前页面。
2. 注入reload
方法
inject:['reload']
3.使用
this.reload()