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>
<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

{
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "文档",
      "link": "/quick-start.md"
    },
    {
      "text": "示例",
      "link": "https://a.14star.cn"
    },
    {
      "text": "讨论",
      "link": "https://github.com/SylarLong/iztro/discussions"
    },
    {
      "text": "关于作者",
      "link": "/about.md"
    },
    {
      "text": "<img src=\"https://img.shields.io/github/stars/sylarlong/iztro.svg?style=social&label=Star\" alt=\"iztro\" />",
      "link": "https://github.com/SylarLong/iztro"
    },
    {
      "text": "v1.2.1",
      "items": [
        {
          "text": "更改日志",
          "link": "https://github.com/SylarLong/iztro/blob/main/CHANGELOG.md"
        },
        {
          "text": "NPM地址",
          "link": "https://www.npmjs.com/package/iztro"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "iztro",
      "items": [
        {
          "text": "快速开始",
          "link": "/quick-start.md"
        },
        {
          "text": "类型定义",
          "link": "/type-definition.md"
        },
        {
          "text": "星盘",
          "link": "/posts/astrolabe.md"
        },
        {
          "text": "宫位",
          "link": "/posts/palace.md"
        },
        {
          "text": "星耀",
          "link": "/posts/star.md"
        }
      ]
    },
    {
      "text": "紫微斗数",
      "items": [
        {
          "text": "基础扫盲",
          "link": "/learn/basis.md"
        },
        {
          "text": "宫位知识",
          "link": "/learn/palace.md"
        },
        {
          "text": "星耀知识",
          "link": "/learn/star.md",
          "items": [
            {
              "text": "14主星",
              "link": "/learn/major-star.md"
            },
            {
              "text": "14辅星",
              "link": "/learn/minor-star.md"
            },
            {
              "text": "37杂耀",
              "link": "/learn/adj-star.md"
            },
            {
              "text": "48神煞",
              "link": "/learn/dec-star.md"
            }
          ]
        },
        {
          "text": "四化",
          "link": "/learn/mutagen.md"
        },
        {
          "text": "运限",
          "link": "/learn/horoscope.md"
        },
        {
          "text": "安星诀",
          "link": "/learn/setup.md"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/SylarLong/iztro"
    }
  ],
  "outlineTitle": "页内导航"
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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