provide、inject
app.vue中:
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
</div>
</template>
data(){
return{
isRouterAlive:true
}
}
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(() => {
this.isRouterAlive = true;
});
},
},
provide(){
return{
reload:this.reload
}
},
在使用刷新的页面:
inject: ["reload"]
this.reload()刷新页面,只刷新了内容区域