提交 ece2e1e0 编写于 作者: U ULIVZ

fix($core): "slotKey" must be defined as props in user's markdown's script tag (close: #975)

上级 a56c3b4b
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('')
}
......
......@@ -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;
}
</style>
......@@ -14,7 +14,7 @@ declare class VuePress extends Store {
}
declare module "vue/types/vue" {
interface Vue {
export interface Vue {
$vuepress: VuePress;
}
}
export default {
created () {
this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
this.$vuepress.$set('contentMounted', true)
})
},
watch: {
'$route.path' () {
this.$vuepress.$set('contentMounted', false)
}
}
}
......@@ -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 = [
......
......@@ -100,18 +100,8 @@ module.exports = function (src) {
const res = (
`<template>\n` +
`<ContentSlotsDistributor :slot-key="slotKey">${html}</ContentSlotsDistributor>\n` +
`<ContentSlotsDistributor :slot-key="$parent.slotKey">${html}</ContentSlotsDistributor>\n` +
`</template>\n` +
`<script>
export default {
props: ['slot-key'],
mounted() {
this.$nextTick(function () {
this.$vuepress.$emit('AsyncMarkdownContentMounted', this.slotKey)
})
}
}
</script>` +
(hoistedTags || []).join('\n') +
`\n${dataBlockString}\n`
)
......
......@@ -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)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册