(1)控制router的显示与隐藏
// App.vue
<template>
<div id="app">
<router-view v-if="routerAlive"/>
</div>
</template>
<script>
export default {
name: 'app',
provide(){
return{
reload:this.reload
}
},
data() {
return {
routerAlive:true,
}
},
methods: {
reload(){
this.routerAlive=false;
this.$nextTick(function(){
this.routerAlive=true;
})
}
},
}
</script>
(2)在要刷新的组件引入inject
export default {
inject: ['reload'],
methods:{
reloadBtn(){ //刷新事件
this.reload(); //调用reload方法
}
}
}