vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.29k stars 925 forks source link

[Feature request] explain how to register global component and maybe give an example #113

Closed JulioJu closed 3 years ago

JulioJu commented 3 years ago

Feature request

Description

Currently on the doc there is no information to know how to register global component.

We only know at https://vuepress2.netlify.app/guide/migration.html#for-plugin-authors

Files in theme/global-components/ directory will not be registered as Vue components automatically. You need to register components manually in clientAppEnhance.{js,ts}.

There is no more information at https://vuepress2.netlify.app/reference/client-api.html#usepagelang

To know how to register Global Component I've checked the Source Code

Proposed Solution

Add somewhere an example that we could register a global component like

import { defineClientAppEnhance } from "@vuepress/client";
import Test from "./global-components/Test.vue";

export default defineClientAppEnhance(({ app }) => {
  app.component("Test", Test);
});

Furthermore, for newbies, it could be interesting to explain what is a global component. Just say that global components are interesting because they could be used into Markdown files and they could be used in any Vue file of the project without be imported.

A link to the example could be added into migration guide https://vuepress2.netlify.app/guide/migration.html#for-plugin-authors .

meteorlxy commented 3 years ago

We are planing to add more examples or provide a cookbook for how to write a plugin / theme.