vue實現F5刷新整個頁面無空白無間隔時間
通過
this.$router.go(0)
刷新頁面,和F5一樣,會有空白頁時間,體驗不好。通過provide/inject
即可改變這種效果。
- 首先在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();