Skip to content

Commit 362cdf7

Browse files
committed
refactor: distinguish between first screen loading and route switching
1 parent 26411e9 commit 362cdf7

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

packages/@vuepress/core/lib/app/components/Content.vue

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<template>
2-
<component :is="layout" :slot-key="slotKey || 'default'"/>
2+
<transition :name="layout === 'ContentLoading' || !layout ? null : 'fade'">
3+
<component
4+
v-if="layout"
5+
:is="layout"
6+
:slot-key="slotKey || 'default'"
7+
/>
8+
<div v-else class="conent"></div>
9+
</transition>
310
</template>
411

512
<script>
@@ -33,12 +40,22 @@ export default {
3340
3441
watch: {
3542
$key (key) {
36-
this.loadContent(key)
43+
this.reloadContent(key)
3744
}
3845
},
3946
4047
methods: {
4148
loadContent (pageKey) {
49+
this.layout = null
50+
if (components[pageKey]) {
51+
if (!this.$ssrContext) {
52+
Vue.component(pageKey, components[pageKey])
53+
this.layout = pageKey
54+
}
55+
}
56+
},
57+
58+
reloadContent (pageKey) {
4259
if (Vue.component(pageKey)) {
4360
return
4461
}
@@ -47,15 +64,27 @@ export default {
4764
if (!this.$ssrContext) {
4865
Promise.all([
4966
components[pageKey](),
50-
new Promise(resolve => setTimeout(resolve, 0))
67+
new Promise(resolve => setTimeout(resolve, 300))
5168
]).then(([comp]) => {
5269
this.$vuepress.$emit('AsyncMarkdownAssetLoaded', this.pageKey)
5370
Vue.component(pageKey, comp.default)
54-
this.layout = pageKey
71+
this.layout = null
72+
setTimeout(() => {
73+
this.layout = pageKey
74+
})
5575
})
5676
}
5777
}
5878
}
5979
}
6080
}
6181
</script>
82+
83+
<style>
84+
.fade-enter-active, .fade-leave-active {
85+
transition: opacity .3s;
86+
}
87+
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
88+
opacity: 0;
89+
}
90+
</style>

0 commit comments

Comments
 (0)