使用this.$router.go(0)刷新页面,和F5一样,会有空白页时间。
可以通过provide / inject即可改变这种效果。
1 . 首先在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>
<style></style>
2 . 然后在具体页面中加上inject配置,具体如下:
// 那个页面需要使用加上这两段代码
inject: ['reload'],
this.reload();