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

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

九、第三方组件库的使用

我们经常看见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标签,不了解的话可以去搜索看下。

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

在线预览效果:Button 按钮 | 前端吧

github地址:GitHub - msyuan/vitePress-project: 基于vitePress搭建的个人轻型博客项目,从零开始详解搭建过程

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值