从零用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最新版本使用-第三方组件库的使用和搭建组件库文档

相关推荐
GDAL10 天前
VitePress 文件路由解析:从 Markdown 到 HTML 的映射艺术
前端·html·vitepress
大宝贱1 个月前
基于ffmpeg.wasm实现的视频格式转换工具
ffmpeg·wasm·webassembly·vitepress·视频格式转换
Justin3go2 个月前
第三次重构个人博客(基于Vitepress)
前端·vue.js·vitepress
粥里有勺糖3 个月前
博客构建性能优化笔记 | 提速 3 倍
vitepress
橙红年代4 个月前
在VitePress中实现内联Vue组件
前端·vue.js·vitepress
gqkmiss5 个月前
使用 Vitepress 构建博客并部署到 github 平台
前端·前端框架·vue·github·博客·vitepress
gqkmiss5 个月前
VitePress 构建的博客如何部署到 Netlify 平台?
github·博客·vitepress·netlify
gqkmiss5 个月前
VitePress 构建的博客如何部署到 github 平台?
vue·github·vitepress
MiyueFE5 个月前
【TeaTools/auto-sync-blog】掘金下午茶团队自动化掘金文章同步工具 2.0 发布啦~~
前端·vitepress
无声20175 个月前
VitePress 实现归档与标签分类
前端·vitepress