App.vue注入以下代码,以下所示:
//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
}
},
components: {
},
data: function() {
return {
isRouterAlive:true
}
},
methods:{
reload: function(){
this.isRouterAlive=false;
this.$nextTick(function(){
this.isRouterAlive =true;
});
},
}
}
</script>
在需要的页面引入reload,如下所示:
调用reload方法,如图所示: