使用provide和inject结合的方法。此方法着实有效,不会有闪烁的空白出现
App.vue
<template>
<div id="app">
<router-view v-if="isRouterAlive"/>
</div>
</template>
<script>
export default {
name: 'app',
provide() {
return {
reload: this.reload
}
},
data() {
return {
isRouterAlive: true
}
},
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
</script>
实现页面刷新
export default {
inject: ['reload'], //新加入的 注入reload方法
data(){
return{
......
}
},
methods: {
save() {
this.$api.savegoods(this.goods).then(res => {
if (res.code == 200) {
this.$message("保存成功");
this.clearGoods();
} else {
this.$message.error(res.msg);
}
this.reload(); //页面刷新 直接调用
})
})
},