File tree 1 file changed +33
-4
lines changed
packages/@vuepress/core/lib/app/components
1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change 1
1
<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 >
3
10
</template >
4
11
5
12
<script >
@@ -33,12 +40,22 @@ export default {
33
40
34
41
watch: {
35
42
$key (key) {
36
- this .loadContent (key)
43
+ this .reloadContent (key)
37
44
}
38
45
},
39
46
40
47
methods: {
41
48
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 ) {
42
59
if (Vue .component (pageKey)) {
43
60
return
44
61
}
@@ -47,15 +64,27 @@ export default {
47
64
if (! this .$ssrContext ) {
48
65
Promise .all ([
49
66
components[pageKey](),
50
- new Promise (resolve => setTimeout (resolve, 0 ))
67
+ new Promise (resolve => setTimeout (resolve, 300 ))
51
68
]).then (([comp ]) => {
52
69
this .$vuepress .$emit (' AsyncMarkdownAssetLoaded' , this .pageKey )
53
70
Vue .component (pageKey, comp .default )
54
- this .layout = pageKey
71
+ this .layout = null
72
+ setTimeout (() => {
73
+ this .layout = pageKey
74
+ })
55
75
})
56
76
}
57
77
}
58
78
}
59
79
}
60
80
}
61
81
</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 >
You can’t perform that action at this time.
0 commit comments