从零用VitePress搭建博客教程(6) -– 第三方组件库的使用和VitePress搭建组件库文档

接上一节:从零用VitePress搭建博客教程(5) - 如何自定义页面模板、给页面添加独有的className和使页面标题变成侧边目录?

九、第三方组件库的使用

我们经常看见UI组件库的文档,这里我们就用element-plus第三方组件库为例子,搭建组件库文档

examples:作为组件库示例目录,我们以Button组件使用为例

1、安装element-plus

复制代码
pnpm install element-plus

2、引入element-plus

安装完成后,在theme/index.js引入element-plus相关文件

复制代码
import DefaultTheme from "vitepress/theme";
 
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
 
export default {
  ...DefaultTheme,
  NotFound: () => "404", // <- this is a Vue 3 functional component
  enhanceApp({ app, router, siteData }) {
    // app is the Vue 3 app instance from createApp()
    // router is VitePress' custom router (see `lib/app/router.js`)
    // siteData is a ref of current site-level metadata.
    app.use(ElementPlus);
  },
};

3、编写button.md文档

复制代码
# Button 按钮
 
## 基础用法
 
<div class="ui-button">
  <el-button type="primary">主要按钮</el-button>
  <el-button type="success">绿色按钮</el-button>
  <el-button type="info">灰色按钮</el-button>
  <el-button type="warning">黄色按钮</el-button>
  <el-button type="danger">红色按钮</el-button>
</div>
 
<details>
  <summary>查看代码</summary>
 
``` vue
<template>
  <el-button type="primary">主要按钮</el-button>
  <el-button type="success">绿色按钮</el-button>
  <el-button type="info">灰色按钮</el-button>
  <el-button type="warning">黄色按钮</el-button>
  <el-button type="danger">红色按钮</el-button>
</template>
```
 
</details>
 
 
### plain用法
 
<div class="ui-button">
  <el-button type="primary" plain>主要按钮</el-button>
  <el-button type="success" plain>绿色按钮</el-button>
  <el-button type="info" plain>灰色按钮</el-button>
  <el-button type="warning" plain>黄色按钮</el-button>
  <el-button type="danger" plain>红色按钮</el-button>
</div>
 
::: details CODE
 
``` vue
<el-button type="primary" plain>主要按钮</el-button>
<el-button type="success" plain>绿色按钮</el-button>
<el-button type="info" plain>灰色按钮</el-button>
<el-button type="warning" plain>黄色按钮</el-button>
<el-button type="danger" plain>红色按钮</el-button>
```
:::

这里用到html5的details和summary标签,不了解的话可以去搜索看下。

然后配置一个"组件使用"的头部导航,效果如下:

在线预览效果:https://msyuan.github.io/vitePress-project/examples/button.html

github地址:https://github.com/msyuan/vitePress-project
原文地址:VitePress最新版本使用-第三方组件库的使用和搭建组件库文档

相关推荐
前端大卫8 天前
超简单!3 步搭建免费个人 Blog!【附源码】
vue.js·vitepress·前端工程化
粉蓝小兔12 天前
将vitepress项目部署在github pages
vitepress
_jiang20 天前
AI 生成的 Markdown 无法直接分享怎么办?写一个 Markdown to 在线 HTML 链接转换器
前端·ai编程·vitepress
taojiahong1 个月前
Vitepress+EdgeOne Pages快速迁移旧网站内容
javascript·python·vitepress
Wan-deuk-i1 个月前
Vitepress+EdgeOne Pages快速迁移旧网站内容
javascript·python·vitepress
每天进步一大步2 个月前
vitePress实现原理(四)
前端·javascript·vue.js·vitepress
夕水3 个月前
你可能不知道的vitepress扩展-1
前端·vitepress
清灵xmf4 个月前
简单介绍下 VitePress 中的 vp-doc 和 vp-raw
javascript·vue.js·vitepress·vp-doc·vp-raw
r0ad7 个月前
简单使用vitepress快速搭建一个文档网站
vitepress
游仙好梦7 个月前
Vitepress 自定义主题开发教程
前端·开源·vitepress