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

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "Table of Contents",
      "items": [
        {
          "text": "agent-server",
          "link": "/agent-server"
        },
        {
          "text": "akgstudio",
          "items": [
            {
              "text": "akgapp",
              "items": [
                {
                  "text": "agent",
                  "items": [
                    {
                      "text": "inbox",
                      "link": "/akgstudio/akgapp/agent/inbox"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "laptop",
                  "items": [
                    {
                      "text": "inbox",
                      "link": "/akgstudio/akgapp/laptop/inbox"
                    }
                  ],
                  "collapsed": true
                }
              ],
              "collapsed": true
            },
            {
              "text": "akggame",
              "items": [
                {
                  "text": "akggame",
                  "link": "/akgstudio/akggame/akggame"
                },
                {
                  "text": "classic_game_server",
                  "items": [
                    {
                      "text": "battleserver",
                      "items": [
                        {
                          "text": "code",
                          "items": [
                            {
                              "text": "camera_slider",
                              "link": "/akgstudio/akggame/classic_game_server/battleserver/code/camera_slider"
                            },
                            {
                              "text": "login",
                              "link": "/akgstudio/akggame/classic_game_server/battleserver/code/login"
                            }
                          ],
                          "collapsed": true
                        },
                        {
                          "text": "config",
                          "items": [
                            {
                              "text": "itemconfig",
                              "link": "/akgstudio/akggame/classic_game_server/battleserver/config/itemconfig"
                            }
                          ],
                          "collapsed": true
                        }
                      ],
                      "collapsed": true
                    },
                    {
                      "text": "dnf",
                      "items": [
                        {
                          "text": "dnf",
                          "link": "/akgstudio/akggame/classic_game_server/dnf/dnf"
                        }
                      ],
                      "collapsed": true
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "domino",
                  "link": "/akgstudio/akggame/domino"
                },
                {
                  "text": "game-dev",
                  "items": [
                    {
                      "text": "game-for-me",
                      "link": "/akgstudio/akggame/game-dev/game-for-me"
                    },
                    {
                      "text": "game-frame",
                      "link": "/akgstudio/akggame/game-dev/game-frame"
                    },
                    {
                      "text": "inbox",
                      "link": "/akgstudio/akggame/game-dev/inbox"
                    },
                    {
                      "text": "unityhub",
                      "link": "/akgstudio/akggame/game-dev/unityhub"
                    },
                    {
                      "text": "收入",
                      "link": "/akgstudio/akggame/game-dev/收入"
                    },
                    {
                      "text": "最后一战",
                      "link": "/akgstudio/akggame/game-dev/最后一战"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "inbox",
                  "link": "/akgstudio/akggame/inbox"
                },
                {
                  "text": "track_simulator",
                  "items": [
                    {
                      "text": "track_life",
                      "link": "/akgstudio/akggame/track_simulator/track_life"
                    }
                  ],
                  "collapsed": true
                }
              ],
              "collapsed": true
            },
            {
              "text": "akglibre",
              "items": [
                {
                  "text": "librevpn",
                  "items": [
                    {
                      "text": "openvpn",
                      "link": "/akgstudio/akglibre/librevpn/openvpn"
                    },
                    {
                      "text": "wireguard",
                      "link": "/akgstudio/akglibre/librevpn/wireguard"
                    }
                  ],
                  "collapsed": true
                }
              ],
              "collapsed": true
            },
            {
              "text": "akgphone",
              "items": [
                {
                  "text": "device",
                  "link": "/akgstudio/akgphone/device"
                },
                {
                  "text": "fairphone",
                  "items": [
                    {
                      "text": "fairphone_boot",
                      "link": "/akgstudio/akgphone/fairphone/fairphone_boot"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "inbox",
                  "link": "/akgstudio/akgphone/inbox"
                },
                {
                  "text": "pmos",
                  "items": [
                    {
                      "text": "inbox",
                      "link": "/akgstudio/akgphone/pmos/inbox"
                    },
                    {
                      "text": "sxmo",
                      "items": [
                        {
                          "text": "basic_config",
                          "link": "/akgstudio/akgphone/pmos/sxmo/basic_config"
                        }
                      ],
                      "collapsed": true
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "samsung",
                  "items": [
                    {
                      "text": "a3000",
                      "link": "/akgstudio/akgphone/samsung/a3000"
                    },
                    {
                      "text": "issue",
                      "link": "/akgstudio/akgphone/samsung/issue"
                    },
                    {
                      "text": "postmarketos",
                      "link": "/akgstudio/akgphone/samsung/postmarketos"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "use1_blog",
                  "items": [
                    {
                      "text": "typecho",
                      "link": "/akgstudio/akgphone/use1_blog/typecho"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "xiaomi",
                  "items": [
                    {
                      "text": "postmarketos",
                      "link": "/akgstudio/akgphone/xiaomi/postmarketos"
                    },
                    {
                      "text": "use",
                      "link": "/akgstudio/akgphone/xiaomi/use"
                    },
                    {
                      "text": "xiaomi2",
                      "link": "/akgstudio/akgphone/xiaomi/xiaomi2"
                    }
                  ],
                  "collapsed": true
                }
              ],
              "collapsed": true
            },
            {
              "text": "akgshop",
              "items": [
                {
                  "text": "eshopphone",
                  "link": "/akgstudio/akgshop/eshopphone"
                },
                {
                  "text": "hok",
                  "items": [
                    {
                      "text": "inbox",
                      "link": "/akgstudio/akgshop/hok/inbox"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "inbox",
                  "link": "/akgstudio/akgshop/inbox"
                },
                {
                  "text": "route",
                  "items": [
                    {
                      "text": "base_use",
                      "link": "/akgstudio/akgshop/route/base_use"
                    },
                    {
                      "text": "glinet",
                      "link": "/akgstudio/akgshop/route/glinet"
                    }
                  ],
                  "collapsed": true
                }
              ],
              "collapsed": true
            },
            {
              "text": "akgwriter",
              "items": [
                {
                  "text": "在小说里实现梦想又怎样",
                  "link": "/akgstudio/akgwriter/在小说里实现梦想又怎样"
                }
              ],
              "collapsed": true
            },
            {
              "text": "flashos",
              "items": [
                {
                  "text": "cmcc_route",
                  "link": "/akgstudio/flashos/cmcc_route"
                }
              ],
              "collapsed": true
            },
            {
              "text": "wemedia",
              "items": [
                {
                  "text": "floss",
                  "link": "/akgstudio/wemedia/floss"
                },
                {
                  "text": "inbox",
                  "link": "/akgstudio/wemedia/inbox"
                },
                {
                  "text": "tutlab",
                  "items": [
                    {
                      "text": "csharp",
                      "link": "/akgstudio/wemedia/tutlab/csharp"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "tutlab",
                  "link": "/akgstudio/wemedia/tutlab"
                }
              ],
              "collapsed": true
            }
          ],
          "collapsed": true
        },
        {
          "text": "api-examples",
          "link": "/api-examples"
        },
        {
          "text": "auto",
          "items": [
            {
              "text": "akgstudio",
              "link": "/auto/akgstudio"
            },
            {
              "text": "lrappsoft",
              "link": "/auto/lrappsoft"
            }
          ],
          "collapsed": true
        },
        {
          "text": "buildadmin",
          "items": [
            {
              "text": "crud-introduce",
              "link": "/buildadmin/crud-introduce"
            },
            {
              "text": "index",
              "link": "/buildadmin/index"
            },
            {
              "text": "mail-config",
              "link": "/buildadmin/mail-config"
            }
          ],
          "collapsed": true
        },
        {
          "text": "c-dev",
          "items": [
            {
              "text": "c-oop",
              "link": "/c-dev/c-oop"
            },
            {
              "text": "c-server",
              "link": "/c-dev/c-server"
            },
            {
              "text": "c-socket",
              "link": "/c-dev/c-socket"
            },
            {
              "text": "cmake",
              "link": "/c-dev/cmake"
            },
            {
              "text": "env",
              "link": "/c-dev/env"
            },
            {
              "text": "lwan",
              "items": [
                {
                  "text": "lwan",
                  "link": "/c-dev/lwan/lwan"
                }
              ],
              "collapsed": true
            },
            {
              "text": "opengl",
              "link": "/c-dev/opengl"
            },
            {
              "text": "sdl",
              "link": "/c-dev/sdl"
            },
            {
              "text": "tts",
              "items": [
                {
                  "text": "espeak",
                  "link": "/c-dev/tts/espeak"
                }
              ],
              "collapsed": true
            }
          ],
          "collapsed": true
        },
        {
          "text": "cocos-creator",
          "items": [
            {
              "text": "ThreeKingdoms2D",
              "link": "/cocos-creator/ThreeKingdoms2D"
            },
            {
              "text": "ThreeKingdoms2Dserver",
              "link": "/cocos-creator/ThreeKingdoms2Dserver"
            },
            {
              "text": "bug",
              "link": "/cocos-creator/bug"
            },
            {
              "text": "cocos-creator-shotcuts",
              "link": "/cocos-creator/cocos-creator-shotcuts"
            },
            {
              "text": "code-share",
              "link": "/cocos-creator/code-share"
            },
            {
              "text": "game-table-cheer-up",
              "link": "/cocos-creator/game-table-cheer-up"
            }
          ],
          "collapsed": true
        },
        {
          "text": "db",
          "items": [
            {
              "text": "mongodb",
              "link": "/db/mongodb"
            },
            {
              "text": "mysql",
              "link": "/db/mysql"
            }
          ],
          "collapsed": true
        },
        {
          "text": "economy",
          "items": [
            {
              "text": "btc",
              "link": "/economy/btc"
            },
            {
              "text": "inbox",
              "link": "/economy/inbox"
            },
            {
              "text": "qinglong",
              "items": [
                {
                  "text": "dailycheckin",
                  "link": "/economy/qinglong/dailycheckin"
                },
                {
                  "text": "githuberror",
                  "link": "/economy/qinglong/githuberror"
                },
                {
                  "text": "jd",
                  "link": "/economy/qinglong/jd"
                }
              ],
              "collapsed": true
            },
            {
              "text": "睡后收入",
              "link": "/economy/睡后收入"
            }
          ],
          "collapsed": true
        },
        {
          "text": "editor",
          "items": [
            {
              "text": "vscode",
              "link": "/editor/vscode"
            }
          ],
          "collapsed": true
        },
        {
          "text": "libre",
          "items": [
            {
              "text": "app",
              "link": "/libre/app"
            },
            {
              "text": "enduser",
              "link": "/libre/enduser"
            },
            {
              "text": "git",
              "items": [
                {
                  "text": "gitlab",
                  "link": "/libre/git/gitlab"
                }
              ],
              "collapsed": true
            },
            {
              "text": "life",
              "items": [
                {
                  "text": "todo",
                  "link": "/libre/life/todo"
                }
              ],
              "collapsed": true
            },
            {
              "text": "rss",
              "link": "/libre/rss"
            },
            {
              "text": "tty-work",
              "items": [
                {
                  "text": "autologin",
                  "link": "/libre/tty-work/autologin"
                },
                {
                  "text": "bluetooth",
                  "link": "/libre/tty-work/bluetooth"
                },
                {
                  "text": "browser",
                  "items": [
                    {
                      "text": "w3m",
                      "link": "/libre/tty-work/browser/w3m"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "c-dev-shortcuts",
                  "link": "/libre/tty-work/c-dev-shortcuts"
                },
                {
                  "text": "chat",
                  "items": [
                    {
                      "text": "irc",
                      "link": "/libre/tty-work/chat/irc"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "editor",
                  "items": [
                    {
                      "text": "vim",
                      "link": "/libre/tty-work/editor/vim"
                    }
                  ],
                  "collapsed": true
                },
                {
                  "text": "fish",
                  "link": "/libre/tty-work/fish"
                },
                {
                  "text": "inbox",
                  "link": "/libre/tty-work/inbox"
                },
                {
                  "text": "mydotfile-git",
                  "link": "/libre/tty-work/mydotfile-git"
                },
                {
                  "text": "scanip",
                  "link": "/libre/tty-work/scanip"
                },
                {
                  "text": "shell-cmd",
                  "link": "/libre/tty-work/shell-cmd"
                },
                {
                  "text": "speedtest",
                  "link": "/libre/tty-work/speedtest"
                },
                {
                  "text": "sway",
                  "link": "/libre/tty-work/sway"
                },
                {
                  "text": "tar",
                  "link": "/libre/tty-work/tar"
                },
                {
                  "text": "tmux-restore",
                  "link": "/libre/tty-work/tmux-restore"
                },
                {
                  "text": "wifi",
                  "link": "/libre/tty-work/wifi"
                },
                {
                  "text": "xfce",
                  "link": "/libre/tty-work/xfce"
                }
              ],
              "collapsed": true
            }
          ],
          "collapsed": true
        },
        {
          "text": "make-this-blog",
          "link": "/make-this-blog"
        },
        {
          "text": "markdown-examples",
          "link": "/markdown-examples"
        },
        {
          "text": "mybody",
          "items": [
            {
              "text": "uc",
              "link": "/mybody/uc"
            }
          ],
          "collapsed": true
        },
        {
          "text": "net",
          "items": [
            {
              "text": "websocket",
              "link": "/net/websocket"
            }
          ],
          "collapsed": true
        },
        {
          "text": "ossuse",
          "items": [
            {
              "text": "sumatrapdf",
              "link": "/ossuse/sumatrapdf"
            }
          ],
          "collapsed": true
        },
        {
          "text": "remake-hok",
          "items": [
            {
              "text": "git",
              "link": "/remake-hok/git"
            }
          ],
          "collapsed": true
        },
        {
          "text": "remake-hxsg",
          "items": [
            {
              "text": "c-version",
              "link": "/remake-hxsg/c-version"
            },
            {
              "text": "html-version",
              "link": "/remake-hxsg/html-version"
            }
          ],
          "collapsed": true
        },
        {
          "text": "ssh",
          "items": [
            {
              "text": "my-questions",
              "link": "/ssh/my-questions"
            },
            {
              "text": "vscode-remote-root",
              "link": "/ssh/vscode-remote-root"
            }
          ],
          "collapsed": true
        },
        {
          "text": "studio",
          "items": [
            {
              "text": "akg工作室",
              "link": "/studio/akg工作室"
            }
          ],
          "collapsed": true
        },
        {
          "text": "todo",
          "items": [
            {
              "text": "buy",
              "link": "/todo/buy"
            },
            {
              "text": "day1110",
              "link": "/todo/day1110"
            },
            {
              "text": "score",
              "link": "/todo/score"
            },
            {
              "text": "today",
              "link": "/todo/today"
            }
          ],
          "collapsed": true
        },
        {
          "text": "ubuntu",
          "items": [
            {
              "text": "https-local",
              "link": "/ubuntu/https-local"
            },
            {
              "text": "nginx-install",
              "link": "/ubuntu/nginx-install"
            },
            {
              "text": "samba",
              "link": "/ubuntu/samba"
            },
            {
              "text": "ubuntu-touch",
              "items": [
                {
                  "text": "intro",
                  "link": "/ubuntu/ubuntu-touch/intro"
                }
              ],
              "collapsed": true
            },
            {
              "text": "xfce",
              "link": "/ubuntu/xfce"
            }
          ],
          "collapsed": true
        },
        {
          "text": "vcs",
          "items": [
            {
              "text": "git",
              "link": "/vcs/git"
            },
            {
              "text": "svn",
              "link": "/vcs/svn"
            }
          ],
          "collapsed": true
        },
        {
          "text": "web",
          "items": [
            {
              "text": "npm",
              "link": "/web/npm"
            }
          ],
          "collapsed": true
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

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.