Skip to content

Commit 704031f

Browse files
committed
fix($core): content slots doesn't work
1 parent cfd0113 commit 704031f

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

packages/@vuepress/core/lib/app/app.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Store from './Store'
1111

1212
// built-in components
1313
import Content from './components/Content'
14+
import ContentSlotsDistributor from './components/ContentSlotsDistributor'
1415
import OutboundLink from './components/OutboundLink.vue'
1516
import ClientOnly from './components/ClientOnly'
1617

@@ -36,6 +37,7 @@ Vue.use(Router)
3637
Vue.mixin(dataMixin(ClientComputedMixin, siteData))
3738
// component for rendering markdown content and setting title etc.
3839
Vue.component('Content', Content)
40+
Vue.component('ContentSlotsDistributor', ContentSlotsDistributor)
3941
Vue.component('OutboundLink', OutboundLink)
4042
// component for client-only content
4143
Vue.component('ClientOnly', ClientOnly)

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export default {
2222
return h(pageKey, {
2323
class: [data.class, data.staticClass],
2424
style: data.style,
25-
slot: props.slot || 'default'
25+
props: {
26+
slotKey: props.slot || 'default'
27+
}
2628
})
2729
}
2830
return h('')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
functional: true,
3+
props: {
4+
slotKey: String,
5+
required: true
6+
},
7+
render (h, { props, slots }) {
8+
console.log(props.slotKey)
9+
return h('div',
10+
{
11+
class: [
12+
'content',
13+
props.slotKey
14+
]
15+
},
16+
slots()[props.slotKey]
17+
)
18+
}
19+
}

packages/@vuepress/markdown-loader/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ module.exports = function (src) {
100100

101101
const res = (
102102
`<template>\n` +
103-
`<div class="content">${html}</div>\n` +
103+
`<ContentSlotsDistributor :slot-key="slotKey">${html}</ContentSlotsDistributor>\n` +
104104
`</template>\n` +
105+
`<script>export default { props: ['slot-key'] }</script>` +
105106
(hoistedTags || []).join('\n') +
106107
`\n${dataBlockString}\n`
107108
)

0 commit comments

Comments
 (0)