跳至主要內容

组件

小于 1 分钟

你可以在 Markdown 中轻松添加组件。

配置

import { mdEnhancePlugin } from "vuepress-plugin-md-enhance";

export default {
  plugins: [
    mdEnhancePlugin({
      // 开启组件支持
      component: true,
    }),
  ],
};






 



使用

你可以使用 component 代码块来在 Markdown 中添加组件。YAML 和 JSON 的数据格式均受支持:

  • YAML 推荐:

    ```component 组件名称
    # 组件数据
    ```
    
  • JSON:

    ```component 组件名称
    {
      // 组件数据
    }
    ```
    

案例

快速使用 VPCard 组件
```component VPCard
title: Mr.Hope
desc: Where there is light, there is hope
logo: https://mister-hope.com/logo.svg
link: https://mister-hope.com
background: rgba(253, 230, 138, 0.15)
```

```component VPCard
{
  "title": "Mr.Hope",
  "desc": "Where there is light, there is hope",
  "logo": "https://mister-hope.com/logo.svg",
  "link": "https://mister-hope.com",
  "background": "rgba(253, 230, 138, 0.15)"
}
```

这里的 <VPCard> 是已经全局注册的卡片组件。

上方的代码块和下方等价:

<VPCard
  title="Mr.Hope"
  desc="Where there is light, there is hope"
  logo="https://mister-hope.com/logo.svg"
  link="https://mister-hope.com"
  background="rgba(253, 230, 138, 0.15)"
/>