logo
Runtime API ExamplesRuntime API Examples

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>
{
  "defaultColor": "#39c5bb",
  "defaultImpression": "/assets/images/121337686_p0.webp",
  "siteVersion": "0.0.1",
  "navSegment": [
    {
      "text": "首页",
      "icon": "home",
      "link": "/"
    },
    {
      "text": "AincradMix",
      "icon": "borg",
      "link": "/posts/AincradMix"
    },
    {
      "text": "作品集",
      "icon": "auto_awesome_mosaic",
      "link": "https://sendevia.cn53.ug.link/photo/share/?id=4&pagetype=share&uuid=b6f1b05f-5027-451b-b21f-81cae88125e9#/login"
    }
  ]
}
{
  "title": "Runtime API Examples",
  "description": "Runtime API Examples",
  "frontmatter": {
    "title": "Runtime API Examples",
    "description": "Runtime API Examples",
    "color": "",
    "impression": "",
    "categories": null,
    "tags": null,
    "date": "2007-08-31T00:00:00.000Z"
  },
  "headers": [],
  "relativePath": "posts/api-examples.md",
  "filePath": "posts/api-examples.md"
}

Page Frontmatter

复制链接
{
  "title": "Runtime API Examples",
  "description": "Runtime API Examples",
  "color": "",
  "impression": "",
  "categories": null,
  "tags": null,
  "date": "2007-08-31T00:00:00.000Z"
}

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

在此页上

Runtime API Examples

arrow_upward