Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/snowykami/mbcp"
    }
  ],
  "sidebar": {
    "/api/": [
      {
        "text": "api",
        "items": [
          {
            "text": "mbcp",
            "link": "/api/index.md"
          },
          {
            "text": "mp_math",
            "items": [
              {
                "text": "mbcp.mp_math",
                "link": "/api/mp_math/index.md"
              },
              {
                "text": "mbcp.mp_math.angle",
                "link": "/api/mp_math/angle.md"
              },
              {
                "text": "mbcp.mp_math.const",
                "link": "/api/mp_math/const.md"
              },
              {
                "text": "mbcp.mp_math.equation",
                "link": "/api/mp_math/equation.md"
              },
              {
                "text": "mbcp.mp_math.line",
                "link": "/api/mp_math/line.md"
              },
              {
                "text": "mbcp.mp_math.mp_math_typing",
                "link": "/api/mp_math/mp_math_typing.md"
              },
              {
                "text": "mbcp.mp_math.plane",
                "link": "/api/mp_math/plane.md"
              },
              {
                "text": "mbcp.mp_math.point",
                "link": "/api/mp_math/point.md"
              },
              {
                "text": "mbcp.mp_math.segment",
                "link": "/api/mp_math/segment.md"
              },
              {
                "text": "mbcp.mp_math.utils",
                "link": "/api/mp_math/utils.md"
              },
              {
                "text": "mbcp.mp_math.vector",
                "link": "/api/mp_math/vector.md"
              }
            ]
          },
          {
            "text": "particle",
            "items": [
              {
                "text": "mbcp.particle",
                "link": "/api/particle/index.md"
              }
            ]
          },
          {
            "text": "presets",
            "items": [
              {
                "text": "mbcp.presets",
                "link": "/api/presets/index.md"
              },
              {
                "text": "model",
                "items": [
                  {
                    "text": "mbcp.presets.model",
                    "link": "/api/presets/model/index.md"
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/guide/": [
      {
        "text": "guide",
        "items": [
          {
            "text": "开始不了一点",
            "link": "/guide/index.md"
          }
        ]
      }
    ],
    "/en/": [
      {
        "text": "en",
        "items": [
          {
            "text": "api",
            "items": [
              {
                "text": "mbcp",
                "link": "/en/api/index.md"
              },
              {
                "text": "mp_math",
                "items": [
                  {
                    "text": "mbcp.mp_math",
                    "link": "/en/api/mp_math/index.md"
                  },
                  {
                    "text": "mbcp.mp_math.angle",
                    "link": "/en/api/mp_math/angle.md"
                  },
                  {
                    "text": "mbcp.mp_math.const",
                    "link": "/en/api/mp_math/const.md"
                  },
                  {
                    "text": "mbcp.mp_math.equation",
                    "link": "/en/api/mp_math/equation.md"
                  },
                  {
                    "text": "mbcp.mp_math.line",
                    "link": "/en/api/mp_math/line.md"
                  },
                  {
                    "text": "mbcp.mp_math.mp_math_typing",
                    "link": "/en/api/mp_math/mp_math_typing.md"
                  },
                  {
                    "text": "mbcp.mp_math.plane",
                    "link": "/en/api/mp_math/plane.md"
                  },
                  {
                    "text": "mbcp.mp_math.point",
                    "link": "/en/api/mp_math/point.md"
                  },
                  {
                    "text": "mbcp.mp_math.segment",
                    "link": "/en/api/mp_math/segment.md"
                  },
                  {
                    "text": "mbcp.mp_math.utils",
                    "link": "/en/api/mp_math/utils.md"
                  },
                  {
                    "text": "mbcp.mp_math.vector",
                    "link": "/en/api/mp_math/vector.md"
                  }
                ]
              },
              {
                "text": "particle",
                "items": [
                  {
                    "text": "mbcp.particle",
                    "link": "/en/api/particle/index.md"
                  }
                ]
              },
              {
                "text": "presets",
                "items": [
                  {
                    "text": "mbcp.presets",
                    "link": "/en/api/presets/index.md"
                  },
                  {
                    "text": "model",
                    "items": [
                      {
                        "text": "mbcp.presets.model",
                        "link": "/en/api/presets/model/index.md"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/ja/": [
      {
        "text": "ja",
        "items": [
          {
            "text": "api",
            "items": [
              {
                "text": "mbcp",
                "link": "/ja/api/index.md"
              },
              {
                "text": "mp_math",
                "items": [
                  {
                    "text": "mbcp.mp_math",
                    "link": "/ja/api/mp_math/index.md"
                  },
                  {
                    "text": "mbcp.mp_math.angle",
                    "link": "/ja/api/mp_math/angle.md"
                  },
                  {
                    "text": "mbcp.mp_math.const",
                    "link": "/ja/api/mp_math/const.md"
                  },
                  {
                    "text": "mbcp.mp_math.equation",
                    "link": "/ja/api/mp_math/equation.md"
                  },
                  {
                    "text": "mbcp.mp_math.line",
                    "link": "/ja/api/mp_math/line.md"
                  },
                  {
                    "text": "mbcp.mp_math.mp_math_typing",
                    "link": "/ja/api/mp_math/mp_math_typing.md"
                  },
                  {
                    "text": "mbcp.mp_math.plane",
                    "link": "/ja/api/mp_math/plane.md"
                  },
                  {
                    "text": "mbcp.mp_math.point",
                    "link": "/ja/api/mp_math/point.md"
                  },
                  {
                    "text": "mbcp.mp_math.segment",
                    "link": "/ja/api/mp_math/segment.md"
                  },
                  {
                    "text": "mbcp.mp_math.utils",
                    "link": "/ja/api/mp_math/utils.md"
                  },
                  {
                    "text": "mbcp.mp_math.vector",
                    "link": "/ja/api/mp_math/vector.md"
                  }
                ]
              },
              {
                "text": "particle",
                "items": [
                  {
                    "text": "mbcp.particle",
                    "link": "/ja/api/particle/index.md"
                  }
                ]
              },
              {
                "text": "presets",
                "items": [
                  {
                    "text": "mbcp.presets",
                    "link": "/ja/api/presets/index.md"
                  },
                  {
                    "text": "model",
                    "items": [
                      {
                        "text": "mbcp.presets.model",
                        "link": "/ja/api/presets/model/index.md"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/zh-Hant/": [
      {
        "text": "zh-hant",
        "items": [
          {
            "text": "api",
            "items": [
              {
                "text": "mbcp",
                "link": "/zh-Hant/api/index.md"
              },
              {
                "text": "mp_math",
                "items": [
                  {
                    "text": "mbcp.mp_math",
                    "link": "/zh-Hant/api/mp_math/index.md"
                  },
                  {
                    "text": "mbcp.mp_math.angle",
                    "link": "/zh-Hant/api/mp_math/angle.md"
                  },
                  {
                    "text": "mbcp.mp_math.const",
                    "link": "/zh-Hant/api/mp_math/const.md"
                  },
                  {
                    "text": "mbcp.mp_math.equation",
                    "link": "/zh-Hant/api/mp_math/equation.md"
                  },
                  {
                    "text": "mbcp.mp_math.line",
                    "link": "/zh-Hant/api/mp_math/line.md"
                  },
                  {
                    "text": "mbcp.mp_math.mp_math_typing",
                    "link": "/zh-Hant/api/mp_math/mp_math_typing.md"
                  },
                  {
                    "text": "mbcp.mp_math.plane",
                    "link": "/zh-Hant/api/mp_math/plane.md"
                  },
                  {
                    "text": "mbcp.mp_math.point",
                    "link": "/zh-Hant/api/mp_math/point.md"
                  },
                  {
                    "text": "mbcp.mp_math.segment",
                    "link": "/zh-Hant/api/mp_math/segment.md"
                  },
                  {
                    "text": "mbcp.mp_math.utils",
                    "link": "/zh-Hant/api/mp_math/utils.md"
                  },
                  {
                    "text": "mbcp.mp_math.vector",
                    "link": "/zh-Hant/api/mp_math/vector.md"
                  }
                ]
              },
              {
                "text": "particle",
                "items": [
                  {
                    "text": "mbcp.particle",
                    "link": "/zh-Hant/api/particle/index.md"
                  }
                ]
              },
              {
                "text": "presets",
                "items": [
                  {
                    "text": "mbcp.presets",
                    "link": "/zh-Hant/api/presets/index.md"
                  },
                  {
                    "text": "model",
                    "items": [
                      {
                        "text": "mbcp.presets.model",
                        "link": "/zh-Hant/api/presets/model/index.md"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/zht/": [
      {
        "text": "zht",
        "items": [
          {
            "text": "api",
            "items": [
              {
                "text": "mbcp",
                "link": "/zht/api/index.md"
              },
              {
                "text": "mp_math",
                "items": [
                  {
                    "text": "mbcp.mp_math",
                    "link": "/zht/api/mp_math/index.md"
                  },
                  {
                    "text": "mbcp.mp_math.angle",
                    "link": "/zht/api/mp_math/angle.md"
                  },
                  {
                    "text": "mbcp.mp_math.const",
                    "link": "/zht/api/mp_math/const.md"
                  },
                  {
                    "text": "mbcp.mp_math.equation",
                    "link": "/zht/api/mp_math/equation.md"
                  },
                  {
                    "text": "mbcp.mp_math.line",
                    "link": "/zht/api/mp_math/line.md"
                  },
                  {
                    "text": "mbcp.mp_math.mp_math_typing",
                    "link": "/zht/api/mp_math/mp_math_typing.md"
                  },
                  {
                    "text": "mbcp.mp_math.plane",
                    "link": "/zht/api/mp_math/plane.md"
                  },
                  {
                    "text": "mbcp.mp_math.point",
                    "link": "/zht/api/mp_math/point.md"
                  },
                  {
                    "text": "mbcp.mp_math.segment",
                    "link": "/zht/api/mp_math/segment.md"
                  },
                  {
                    "text": "mbcp.mp_math.utils",
                    "link": "/zht/api/mp_math/utils.md"
                  },
                  {
                    "text": "mbcp.mp_math.vector",
                    "link": "/zht/api/mp_math/vector.md"
                  }
                ]
              },
              {
                "text": "particle",
                "items": [
                  {
                    "text": "mbcp.particle",
                    "link": "/zht/api/particle/index.md"
                  }
                ]
              },
              {
                "text": "presets",
                "items": [
                  {
                    "text": "mbcp.presets",
                    "link": "/zht/api/presets/index.md"
                  },
                  {
                    "text": "model",
                    "items": [
                      {
                        "text": "mbcp.presets.model",
                        "link": "/zht/api/presets/model/index.md"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/api-ex.md/": [
      {
        "text": "Runtime API Examples",
        "items": []
      }
    ],
    "/md-ex.md/": [
      {
        "text": "Markdown Extension Examples",
        "items": []
      }
    ]
  },
  "nav": [
    {
      "text": "快速开始",
      "link": "/guide/"
    },
    {
      "text": "API文档",
      "link": "/api/"
    },
    {
      "text": "实例",
      "link": "/demo/"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-ex.md",
  "filePath": "api-ex.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.