第一步,修改项目中的App.vue文件
<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(() => {
this.isRouterAlive = true
})
}
}
}
</script>
第二步,在需要刷新的组件下面地方加上:
export default {
inject: ['reload'],
......
}
第三步,在使用的时候调用this.reload().
例如下面:
handleClick() {
this.reload();
},
这样就解决咯