From ece2e1e09ad5e48c48861330bb79f98880f90028 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Thu, 13 Dec 2018 00:24:14 +0800
Subject: [PATCH] fix($core): "slotKey" must be defined as props in user's
markdown's script tag (close: #975)
---
.../core/lib/app/components/Content.js | 18 +++++++-----------
.../core/lib/app/components/Content.vue | 15 ++++++++++++---
.../core/lib/app/plugins/VuePress.d.ts | 2 +-
.../lib/app/root-mixins/updateLoadingState.js | 13 -------------
.../core/lib/internal-plugins/rootMixins.js | 3 +--
packages/@vuepress/markdown-loader/index.js | 12 +-----------
.../plugin-active-header-links/mixin.js | 2 +-
7 files changed, 23 insertions(+), 42 deletions(-)
delete mode 100644 packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js
diff --git a/packages/@vuepress/core/lib/app/components/Content.js b/packages/@vuepress/core/lib/app/components/Content.js
index 0baaf0d108..29e0a628a2 100644
--- a/packages/@vuepress/core/lib/app/components/Content.js
+++ b/packages/@vuepress/core/lib/app/components/Content.js
@@ -1,13 +1,15 @@
import Vue from 'vue'
export default {
- functional: true,
props: {
pageKey: String,
- slotKey: String
+ slotKey: {
+ type: String,
+ default: 'default'
+ }
},
- render (h, { parent, props, data }) {
- const pageKey = props.pageKey || parent.$page.key
+ render (h) {
+ const pageKey = this.pageKey || this.$parent.$page.key
if (Vue.$vuepress.isPageExists(pageKey)) {
// In SSR, if a component is not registered with the component option
// vue-server-renderer will not be able to resovle it.
@@ -15,13 +17,7 @@ export default {
Vue.$vuepress.registerPageAsyncComponent(pageKey)
}
- return h(pageKey, {
- class: [data.class, data.staticClass],
- style: data.style,
- props: {
- slotKey: props.slotKey || 'default'
- }
- })
+ return h(pageKey)
}
return h('')
}
diff --git a/packages/@vuepress/core/lib/app/components/Content.vue b/packages/@vuepress/core/lib/app/components/Content.vue
index 98b8428787..0cc06c5aa7 100644
--- a/packages/@vuepress/core/lib/app/components/Content.vue
+++ b/packages/@vuepress/core/lib/app/components/Content.vue
@@ -24,7 +24,10 @@ export default {
props: {
pageKey: String,
- slotKey: String
+ slotKey: {
+ type: String,
+ default: 'default'
+ }
},
data () {
@@ -72,6 +75,7 @@ export default {
this.noTransition = true
return
}
+
// Start to load unfetched page component.
this.layout = CONTENT_LOADING_COMPONENT
if (this.$vuepress.isPageExists(pageKey)) {
@@ -79,13 +83,17 @@ export default {
if (!this.$ssrContext) {
Promise.all([
this.$vuepress.loadPageAsyncComponent(pageKey),
- new Promise(resolve => setTimeout(resolve, 300))
+ new Promise(resolve => setTimeout(resolve, 1000))
]).then(([comp]) => {
this.$vuepress.$emit('AsyncMarkdownAssetLoaded', this.pageKey)
Vue.component(pageKey, comp.default)
this.layout = null
setTimeout(() => {
this.layout = pageKey
+ setTimeout(() => {
+ this.$vuepress.$set('contentMounted', true)
+ this.$vuepress.$emit('contentMounted', this.slotKey)
+ })
})
})
}
@@ -99,7 +107,8 @@ export default {
.fade-enter-active, .fade-leave-active {
transition: opacity .2s;
}
- .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
+
+ .fade-enter, .fade-leave-to {
opacity: 0;
}
diff --git a/packages/@vuepress/core/lib/app/plugins/VuePress.d.ts b/packages/@vuepress/core/lib/app/plugins/VuePress.d.ts
index c467381eec..ef4cf3782f 100644
--- a/packages/@vuepress/core/lib/app/plugins/VuePress.d.ts
+++ b/packages/@vuepress/core/lib/app/plugins/VuePress.d.ts
@@ -14,7 +14,7 @@ declare class VuePress extends Store {
}
declare module "vue/types/vue" {
- interface Vue {
+ export interface Vue {
$vuepress: VuePress;
}
}
diff --git a/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js b/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js
deleted file mode 100644
index 7de5d9b272..0000000000
--- a/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js
+++ /dev/null
@@ -1,13 +0,0 @@
-export default {
- created () {
- this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
- this.$vuepress.$set('contentMounted', true)
- })
- },
-
- watch: {
- '$route.path' () {
- this.$vuepress.$set('contentMounted', false)
- }
- }
-}
diff --git a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js
index f081bc7b84..929f29f092 100644
--- a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js
+++ b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js
@@ -7,8 +7,7 @@ module.exports = (options, context, api) => ({
// @internal/root-mixins
async clientDynamicModules () {
const builtInRootMixins = [
- path.resolve(__dirname, '../app/root-mixins/updateMeta.js'),
- path.resolve(__dirname, '../app/root-mixins/updateLoadingState.js')
+ path.resolve(__dirname, '../app/root-mixins/updateMeta.js')
]
const rootMixins = [
diff --git a/packages/@vuepress/markdown-loader/index.js b/packages/@vuepress/markdown-loader/index.js
index e12420eaf2..f4fd02ab9b 100644
--- a/packages/@vuepress/markdown-loader/index.js
+++ b/packages/@vuepress/markdown-loader/index.js
@@ -100,18 +100,8 @@ module.exports = function (src) {
const res = (
`\n` +
- `${html}\n` +
+ `${html}\n` +
`\n` +
- `` +
(hoistedTags || []).join('\n') +
`\n${dataBlockString}\n`
)
diff --git a/packages/@vuepress/plugin-active-header-links/mixin.js b/packages/@vuepress/plugin-active-header-links/mixin.js
index 1af5161fe1..f5884190ec 100644
--- a/packages/@vuepress/plugin-active-header-links/mixin.js
+++ b/packages/@vuepress/plugin-active-header-links/mixin.js
@@ -42,7 +42,7 @@ function getAnchors (sidebarLinks) {
export default {
mounted () {
- this.$vuepress.$on('AsyncMarkdownContentMounted', (slotKey) => {
+ this.$vuepress.$on('contentMounted', (slotKey) => {
if (slotKey === 'default') {
window.addEventListener('scroll', this.onScroll)
}