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();