App.vue
<template>
<div id="app">
<router-view v-if='isRouterAlive'/>
div>
template>
<script>
export default {
name: "App",
data() {
return {
isRouterAlive: true
};
},
provide() {
return {
'reload': this.reload
};
},
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(() => {
this.isRouterAlive = true;
});
}
}
};
script>
子组件调用:
inject:['reload'] //注入后,直接this.reload()