Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我想改内部组件的代码。通过文档的例子修改了VPNavBar但是没有任何数据,全是空白。 #4264

Closed
xaitx opened this issue Oct 10, 2024 · 2 comments

Comments

@xaitx
Copy link

xaitx commented Oct 10, 2024

我想改内部组件的代码。通过文档的例子修改了VPNavBar但是没有任何数据,全是空白。
我应该怎样更好的修改内部组件代码。

@Zhengqbbb
Copy link
Contributor

Zhengqbbb commented Oct 10, 2024

是根据这个文档吗:https://vitepress.dev/zh/guide/extending-default-theme#overriding-internal-components

使用 Vite 的 aliases 来用自定义组件替换默认主题的组件

主要是替换为自定义的组件

  1. 如果只是小改动,可以参考本仓库的源码将组件复制到仓库进行改动(且 import 路径可以选择原 vitepress,可以选择使用自己的)https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/components/VPNavBar.vue
  2. 当然你也可以在源码找到需要修改的内部组件,进行替换
<script lang="ts" setup>
import { useWindowScroll } from '@vueuse/core'
import { ref, watchPostEffect } from 'vue'
import { useData } from 'vitepress/dist/client/theme-default/composables/data'
import { useSidebar } from 'vitepress/dist/client/theme-default//composables/sidebar'
import VPNavBarAppearance from 'vitepress/dist/client/theme-default/components/VPNavBarAppearance.vue'
import VPNavBarExtra from 'vitepress/dist/client/theme-default/components/VPNavBarExtra.vue'
import VPNavBarHamburger from 'vitepress/dist/client/theme-default/components/VPNavBarHamburger.vue'
import VPNavBarMenu from 'vitepress/dist/client/theme-default/components/VPNavBarMenu.vue'
import VPNavBarSearch from 'vitepress/dist/client/theme-default/components/VPNavBarSearch.vue'
import VPNavBarSocialLinks from 'vitepress/dist/client/theme-default/components/VPNavBarSocialLinks.vue'
import VPNavBarTitle from 'vitepress/dist/client/theme-default/components/VPNavBarTitle.vue'
import VPNavBarTranslations from 'vitepress/dist/client/theme-default/components/VPNavBarTranslations.vue'

const props = defineProps<{
  isScreenOpen: boolean
}>()

...

@xaitx
Copy link
Author

xaitx commented Oct 11, 2024

是根据这个文档吗:https://vitepress.dev/zh/guide/extending-default-theme#overriding-internal-components

使用 Vite 的 aliases 来用自定义组件替换默认主题的组件

主要是替换为自定义的组件

  1. 如果只是小改动,可以参考本仓库的源码将组件复制到仓库进行改动(且 import 路径可以选择原 vitepress,可以选择使用自己的)https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/components/VPNavBar.vue
  2. 当然你也可以在源码找到需要修改的内部组件,进行替换
<script lang="ts" setup>
import { useWindowScroll } from '@vueuse/core'
import { ref, watchPostEffect } from 'vue'
import { useData } from 'vitepress/dist/client/theme-default/composables/data'
import { useSidebar } from 'vitepress/dist/client/theme-default//composables/sidebar'
import VPNavBarAppearance from 'vitepress/dist/client/theme-default/components/VPNavBarAppearance.vue'
import VPNavBarExtra from 'vitepress/dist/client/theme-default/components/VPNavBarExtra.vue'
import VPNavBarHamburger from 'vitepress/dist/client/theme-default/components/VPNavBarHamburger.vue'
import VPNavBarMenu from 'vitepress/dist/client/theme-default/components/VPNavBarMenu.vue'
import VPNavBarSearch from 'vitepress/dist/client/theme-default/components/VPNavBarSearch.vue'
import VPNavBarSocialLinks from 'vitepress/dist/client/theme-default/components/VPNavBarSocialLinks.vue'
import VPNavBarTitle from 'vitepress/dist/client/theme-default/components/VPNavBarTitle.vue'
import VPNavBarTranslations from 'vitepress/dist/client/theme-default/components/VPNavBarTranslations.vue'

const props = defineProps<{
  isScreenOpen: boolean
}>()

...

image
我这个是直接将官方源码复制过来知识修改了import 然后在config使用vite替换官方的内部组件

image

这里quan's全是空白

@xaitx xaitx closed this as completed Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants