布局插槽
约 592 字大约 2 分钟
2024-06-17
概述
主题通过 <Layout /> 和 <NotFound /> 提供了丰富的布局插槽,可以通过这些插槽,在页面的不同位置注入内容。 以便用户可以个性化的使用主题。
使用
以 <Layout /> 为例,首先,需要创建一个客户端配置文件: .vuepress/client.ts:
.vuepress/client.ts
import { defineClientConfig } from 'vuepress/client'
import Layout from './layouts/Layout.vue'
export default defineClientConfig({
layouts: {
Layout,
},
})相关信息
layouts 中的 Layout 名是固定的,这是 js 的简写语法, 实际上为 Layout: Layout,它是实现布局插槽的关键。 NotFound 也是相同的规则。
你传入的其它非 Layout / NotFound 的组件,被认为是自定义布局组件。
然后,创建一个 .vuepress/layouts/Layout.vue,作为布局插槽的默认组件,在该组件中引入当前主题的 <Layout /> 组件。
.vuepress/layouts/Layout.vue
<script setup>
import { Layout } from 'vuepress-theme-plume/client'
</script>
<template>
<Layout>
<template #page-bottom>
<div class="custom-content">
自定义内容
</div>
</template>
</Layout>
</template>
<style>
.custom-content {
width: 100%;
}
</style>也可以使用渲染函数实现注入内容,在 .vuepress/client.ts 中:
.vuepress/client.ts
import { h } from 'vue'
import { Layout } from 'vuepress-theme-plume/client'
import { defineClientConfig } from 'vuepress/client'
import CustomContent from './components/CustomContent.vue'
export default defineClientConfig({
layouts: {
Layout: () => h(Layout, null, {
'page-bottom': () => h(CustomContent),
}),
},
}).vuepress/components/CustomContent.vue
<template>
<div class="custom-content">
Custom Content
</div>
</template>插槽
相关信息
您可以预览 https://plume-layout-slots.netlify.app 以查看所有可用的插槽在站点中的位置。
<Layout /> 插槽
当
pageLayout: doc时:doc-topdoc-bottomdoc-content-beforedoc-content-afterdoc-footer-beforedoc-beforedoc-afterdoc-title-beforedoc-title-afterdoc-meta-topdoc-meta-bottomdoc-meta-beforedoc-meta-aftersidebar-nav-beforesidebar-nav-afteraside-topaside-bottomaside-outline-beforeaside-outline-after
当
pageLayout: page时:page-toppage-bottom
在 post 集合相关页面中 (包括文章列表页、标签页、归档页均适用):
posts-topposts-bottomposts-aside-topposts-aside-bottomposts-extract-beforeposts-extract-after
在文章列表页中:
posts-post-list-beforeposts-post-list-afterposts-post-list-pagination-after
在标签页中:
posts-tags-beforeposts-tags-title-afterposts-tags-content-beforeposts-tags-after
在归档页中:
posts-archives-beforeposts-archives-after
在分类页中:
posts-categories-beforeposts-categories-content-beforeposts-categories-after
<NotFound /> 插槽
not-found
通用插槽
以下插槽在 <Layout /> 和 <NotFound /> 中都支持:
layout-toplayout-bottomnav-bar-title-beforenav-bar-title-afternav-bar-content-beforenav-bar-content-afternav-bar-menu-beforenav-bar-menu-afternav-screen-content-beforenav-screen-content-afternav-screen-menu-beforenav-screen-menu-afterfooter-contentbulletin-content
贡献者
更新日志
2026/10/11 04:27
查看所有更新日志
60619-docs: improve docs (#1069)于7f148-feat(theme): adddoc-content-afterslots (#950)于20728-feat(theme): addplugin-llmsand<PageContextMenu />component (#753)于38505-docs: update en docs (#708)于4d236-feat(theme)!: add collections support (#704)于9196d-docs: update layout slots doc于0bced-feat(theme): add layout slots (#558)于97f04-feat(theme): adddoc-meta-beforeanddoc-meta-afterslots (#554)于0fd6c-refactor(theme): improve types and flat config (#524)于6e6f9-docs: improve docs (#509)于
