Skip to content

Commit

Permalink
fix($core): "slotKey" must be defined as props in user's markdown's s…
Browse files Browse the repository at this point in the history
…cript tag (close: #975)
  • Loading branch information
ulivz committed Dec 12, 2018
1 parent a56c3b4 commit ece2e1e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 42 deletions.
18 changes: 7 additions & 11 deletions packages/@vuepress/core/lib/app/components/Content.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
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.
if (!parent.$ssrContext) {
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('')
}
Expand Down
15 changes: 12 additions & 3 deletions packages/@vuepress/core/lib/app/components/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default {
props: {
pageKey: String,
slotKey: String
slotKey: {
type: String,
default: 'default'
}
},
data () {
Expand Down Expand Up @@ -72,20 +75,25 @@ export default {
this.noTransition = true
return
}
// Start to load unfetched page component.
this.layout = CONTENT_LOADING_COMPONENT
if (this.$vuepress.isPageExists(pageKey)) {
this.noTransition = false
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)
})
})
})
}
Expand All @@ -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>
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/app/plugins/VuePress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare class VuePress extends Store {
}

declare module "vue/types/vue" {
interface Vue {
export interface Vue {
$vuepress: VuePress;
}
}
13 changes: 0 additions & 13 deletions packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js

This file was deleted.

3 changes: 1 addition & 2 deletions packages/@vuepress/core/lib/internal-plugins/rootMixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
12 changes: 1 addition & 11 deletions packages/@vuepress/markdown-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/plugin-active-header-links/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ece2e1e

Please sign in to comment.