本人亲测效果最好,借鉴自其他博主,附原文链接:
https://blog.youkuaiyun.com/qq_16772725/article/details/80467492
- 1、修改App.vue,目的通过声明reload方法,控制router-view的显示或隐藏
<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>
<style>
</style>
- 2、页面刷新的页面中注入App.vue组件提供(provide)的 reload 依赖,然后直接用this.reload来调用就行
export default {
inject:['reload'],
methods:{
deletebook (row) {
const _this = this
this.$axios.delete('http://localhost:8181/deleteById/'+row.id).then(function (response) {
// _this.$router.go(0)
_this.reload()//此处调用
})
// this.books.splice(index, 1);
}
}
}