Skip to content

Runtime API Book

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

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Code",
      "link": "/Code/index"
    },
    {
      "text": "Server",
      "link": "/Server/index"
    },
    {
      "text": "Design",
      "link": "/Design/index"
    },
    {
      "text": "APP",
      "link": "/APP/index"
    },
    {
      "text": "Book",
      "link": "/Book/index"
    },
    {
      "text": "Video",
      "link": "/Video/index"
    },
    {
      "text": "Other",
      "link": "/Other/index"
    }
  ],
  "sidebar": {
    "/Code/": [
      {
        "text": "Code",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Code/index"
          }
        ]
      }
    ],
    "/Server/": [
      {
        "text": "Server",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Server/index"
          }
        ]
      }
    ],
    "/Design/": [
      {
        "text": "Design",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Design/index"
          }
        ]
      }
    ],
    "/APP/": [
      {
        "text": "APP",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/APP/index"
          }
        ]
      }
    ],
    "/Book/": [
      {
        "text": "Book",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Book/index"
          }
        ]
      }
    ],
    "/Video/": [
      {
        "text": "Video",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Video/index"
          }
        ]
      }
    ],
    "/Other/": [
      {
        "text": "Other",
        "collapsed": false,
        "items": [
          {
            "text": "Preface",
            "link": "/Other/index"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/binbin-design?tab=repositories"
    }
  ]
}

Page Data

{
  "title": "Runtime API Book",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "Book/index.md",
  "filePath": "Book/index.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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