vuepress-theme-plume/docs/notes/theme/guide/custom/component-overrides.md
pengzhanbo 0fd6cac574
refactor(theme): improve types and flat config (#524)
* refactor(theme): improve types
2025-03-16 02:29:30 +08:00

1.3 KiB

title, icon, createTime, permalink
title icon createTime permalink
组件覆写 carbon:cics-sit-overrides 2024/06/17 16:20:15 /guide/component-overrides/

概述

布局插槽十分实用,但有时候你可能会觉得它不够灵活。主题同样提供了单个组件覆写的能力。

::: warning 在使用此功能前,你应该首先熟悉本主题的源代码,了解 主题内置的各个组件,以便 安全的 覆写他们。

主题的组件源代码托管在 GitHub,遵循 MIT 协议。 :::

使用

主题将所有 非全局的组件 都注册了一个带 @theme 前缀的 alias 。 例如,VPFooter.vue 的别名是 @theme/VPFooter.vue

如果你想要覆写 VPFooter.vue 组件,只需要在配置文件 .vuepress/config.ts 中覆盖这个别名即可:

import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
import { getDirname, path } from 'vuepress/utils'

const __dirname = getDirname(import.meta.url)

export default defineUserConfig({
  theme: plumeTheme(),

  alias: {
    '@theme/VPFooter.vue': path.resolve(
      __dirname,
      './components/MyFooter.vue',
    ),
  },
})