vue刷新当前页,this.$router.go(0)
此方法不友好,回出现一次闪白,
经过尝试最有效的方法为
1.在app.vue中添加 v-if="isRouterAlive"
<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;
})
}
},
components: {
}
};
</script>
2.在需要刷新的页面添加 inject:['reload']
export default {
name: "operateIndex",
inject:['reload'],
props: {},
components: {
approvalTransfer,
assign,
handle,
approved,
caseClosed,
CaseClosed
},
3.在调用接口后直接使用this.reload()方法可刷新当前页
this.$refs.addReply.validate(valid => {
if (valid) {
// console.log(123);
this.addReply.problemNumber = this.problemInfo.problemNumber
this.addReply.problemId = this.problemId
addPhasReply(this.addReply).then(res => {
// console.log(res);
this.$message.success(this.$t('problemIndex.successAddReply'))
this.handleCloseAddReply()
// this.$router.go(0)
this.reload();
})
}
})
个人记录