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

{
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "noResultsText": "无法找到相关结果",
          "resetButtonTitle": "清除查询条件",
          "displayDetails": "显示详细列表",
          "footer": {
            "navigateText": "切换",
            "selectText": "选择",
            "closeText": "关闭"
          }
        }
      }
    }
  },
  "nav": [
    {
      "text": "软考",
      "link": "/ruankao/"
    },
    {
      "text": "在线工具箱",
      "link": "https://mouday.github.io/tools/"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/mouday/coding-tree"
    }
  ],
  "outlineTitle": "导航目录",
  "darkModeSwitchLabel": "外观",
  "sidebarMenuLabel": "菜单",
  "returnToTopLabel": "返回顶部",
  "lastUpdatedText": "上次更新",
  "outline": {
    "level": "deep",
    "label": "大纲"
  },
  "sidebar": {
    "/doc/": [
      {
        "items": [
          {
            "text": "编程语言",
            "link": "/doc/index.html"
          },
          {
            "text": "Python",
            "link": "/doc/python.html"
          }
        ]
      }
    ],
    "/golang/": [
      {
        "items": [
          {
            "text": "3.1、Golang 数组",
            "link": "/golang/golang-array.html"
          },
          {
            "text": "4.5、Golang 并发编程-Mutex 互斥锁实现同步",
            "link": "/golang/golang-concurrency-Mutex.html"
          },
          {
            "text": "4.9、Golang 并发编程-Ticker 周期执行",
            "link": "/golang/golang-concurrency-Ticker.html"
          },
          {
            "text": "4.8、Golang 并发编程-Timer定时器",
            "link": "/golang/golang-concurrency-Timer.html"
          },
          {
            "text": "4.3、Golang 并发编程-WaitGroup实现同步",
            "link": "/golang/golang-concurrency-WaitGroup.html"
          },
          {
            "text": "4.6、Golang 并发编程-atomic原子操作",
            "link": "/golang/golang-concurrency-atomic.html"
          },
          {
            "text": "4.2、Golang 并发编程-channel",
            "link": "/golang/golang-concurrency-channel.html"
          },
          {
            "text": "4.1、Golang 并发编程-协程",
            "link": "/golang/golang-concurrency-goroutines.html"
          },
          {
            "text": "4.4、Golang 并发编程-runtime包",
            "link": "/golang/golang-concurrency-runtime.html"
          },
          {
            "text": "4.7、Golang 并发编程-select switch",
            "link": "/golang/golang-concurrency-select-switch.html"
          },
          {
            "text": "2.3、Golang 常量",
            "link": "/golang/golang-constant.html"
          },
          {
            "text": "2.5、Golang 格式化输出",
            "link": "/golang/golang-format.html"
          },
          {
            "text": "3.4、Golang 函数",
            "link": "/golang/golang-function.html"
          },
          {
            "text": "3.7、Golang接口 interface",
            "link": "/golang/golang-interface.html"
          },
          {
            "text": "3.3、Golang map",
            "link": "/golang/golang-map.html"
          },
          {
            "text": "2.6、Golang 运算符",
            "link": "/golang/golang-operator.html"
          },
          {
            "text": "3.8、Golang包 package",
            "link": "/golang/golang-package.html"
          },
          {
            "text": "3.5、Golang 指针",
            "link": "/golang/golang-pointer.html"
          },
          {
            "text": "2.7、Golang 流程控制",
            "link": "/golang/golang-process.html"
          },
          {
            "text": "3.2、Golang 切片 slice",
            "link": "/golang/golang-slice.html"
          },
          {
            "text": "5.4、Golang标准库-bufio",
            "link": "/golang/golang-standard-bufio.html"
          },
          {
            "text": "5.6、Golang标准库-builtin",
            "link": "/golang/golang-standard-builtin.html"
          },
          {
            "text": "5.7、Golang 标准库-bytes",
            "link": "/golang/golang-standard-bytes.html"
          },
          {
            "text": "5.8、Golang 标准库-errors",
            "link": "/golang/golang-standard-errors.html"
          },
          {
            "text": "5.2、Golang标准库-io输入输出",
            "link": "/golang/golang-standard-io.html"
          },
          {
            "text": "5.3、Golang标准库-ioutil",
            "link": "/golang/golang-standard-ioutil.html"
          },
          {
            "text": "5.11、Golang标准库-json",
            "link": "/golang/golang-standard-json.html"
          },
          {
            "text": "5.5、Golang标准库-log",
            "link": "/golang/golang-standard-log.html"
          },
          {
            "text": "5.13、Golang 标准库-math",
            "link": "/golang/golang-standard-math.html"
          },
          {
            "text": "5.1、Golang标准库-os",
            "link": "/golang/golang-standard-os.html"
          },
          {
            "text": "5.9、Golang标准库-sort",
            "link": "/golang/golang-standard-sort.html"
          },
          {
            "text": "5.10、Golang标准库-time",
            "link": "/golang/golang-standard-time.html"
          },
          {
            "text": "5.12、Golang标准库-xml",
            "link": "/golang/golang-standard-xml.html"
          },
          {
            "text": "3.6、Golang 结构体 struct",
            "link": "/golang/golang-struct.html"
          },
          {
            "text": "2.4、Golang 数据类型",
            "link": "/golang/golang-type.html"
          },
          {
            "text": "笔记: Golang 核心编程",
            "link": "/golang/index.html"
          },
          {
            "text": "1.1、Golang 概述",
            "link": "/golang/101-golang-start.html"
          },
          {
            "text": "1.2、Golang 环境安装",
            "link": "/golang/102-golang-install.html"
          },
          {
            "text": "1.3、Golang 运行代码",
            "link": "/golang/103-golang-run.html"
          },
          {
            "text": "1.4、Golang 项目管理",
            "link": "/golang/104-golang-project.html"
          },
          {
            "text": "2.1、Golang标识符、关键字、命名规则",
            "link": "/golang/201-golang-identifier.html"
          },
          {
            "text": "2.2、Golang变量",
            "link": "/golang/202-golang-variable.html"
          },
          {
            "text": "Golang操作MySQL数据库",
            "link": "/golang/601-golang-mysql.html"
          },
          {
            "text": "Golang操作MongoDB数据库",
            "link": "/golang/602-golang-mongo.html"
          },
          {
            "text": "603-golang-database-redis",
            "link": "/golang/603-golang-database-redis.html"
          },
          {
            "text": "604-golang-gorm",
            "link": "/golang/604-golang-gorm.html"
          },
          {
            "text": "7.1、Go语言Web框架之gin",
            "link": "/golang/701-golang-gin.html"
          }
        ]
      }
    ],
    "/jetbrains/": [
      {
        "items": [
          {
            "text": "jetbrains-2019",
            "link": "/jetbrains/jetbrains-2019.html"
          },
          {
            "text": "jetbrains-2022",
            "link": "/jetbrains/jetbrains-2022.html"
          }
        ]
      }
    ],
    "/public/": [
      {
        "items": [
          {
            "text": "favicon.ico",
            "link": "/public/favicon.ico.html"
          }
        ]
      }
    ],
    "/ruankao/": [
      {
        "items": [
          {
            "text": "软考笔记(2024年5月)",
            "link": "/ruankao/index.html"
          },
          {
            "text": "第1章 信息化发展",
            "link": "/ruankao/chapter-1.html"
          },
          {
            "text": "第2章 信息技术发展",
            "link": "/ruankao/chapter-2.html"
          },
          {
            "text": "第3章 信息系统治理",
            "link": "/ruankao/chapter-3.html"
          },
          {
            "text": "第4章 信息系统管理",
            "link": "/ruankao/chapter-4.html"
          },
          {
            "text": "第5章 信息系统工程",
            "link": "/ruankao/chapter-5.html"
          },
          {
            "text": "第6章 项目管理概论",
            "link": "/ruankao/chapter-6.html"
          },
          {
            "text": "第7章 项目立项管理",
            "link": "/ruankao/chapter-7.html"
          },
          {
            "text": "第8章 项目整合管理",
            "link": "/ruankao/chapter-8.html"
          },
          {
            "text": "第9章 项目范围管理",
            "link": "/ruankao/chapter-9.html"
          },
          {
            "text": "第10章 项目进度管理",
            "link": "/ruankao/chapter-10.html"
          },
          {
            "text": "第11章 项目成本管理",
            "link": "/ruankao/chapter-11.html"
          },
          {
            "text": "第12章 项目质量管理",
            "link": "/ruankao/chapter-12.html"
          },
          {
            "text": "第13章 项目资源管理",
            "link": "/ruankao/chapter-13.html"
          },
          {
            "text": "第14章 项目沟通管理",
            "link": "/ruankao/chapter-14.html"
          },
          {
            "text": "第15章 项目风险管理",
            "link": "/ruankao/chapter-15.html"
          },
          {
            "text": "第16章 项目采购管理",
            "link": "/ruankao/chapter-16.html"
          },
          {
            "text": "第17章 项目干系人管理",
            "link": "/ruankao/chapter-17.html"
          },
          {
            "text": "第18章 项目绩效域",
            "link": "/ruankao/chapter-18.html"
          },
          {
            "text": "第19章 配置与变更管理",
            "link": "/ruankao/chapter-19.html"
          },
          {
            "text": "第20章 高级项目管理",
            "link": "/ruankao/chapter-20.html"
          },
          {
            "text": "第21章 项目管理科学基础",
            "link": "/ruankao/chapter-21.html"
          },
          {
            "text": "第22章 组织通用治理",
            "link": "/ruankao/chapter-22.html"
          },
          {
            "text": "第23章 组织通用管理",
            "link": "/ruankao/chapter-23.html"
          },
          {
            "text": "第24章 法律法规与标准规范",
            "link": "/ruankao/chapter-24.html"
          },
          {
            "text": "知识整合",
            "link": "/ruankao/important-998.html"
          },
          {
            "text": "英文词汇",
            "link": "/ruankao/english-999.html"
          }
        ]
      }
    ]
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

上次更新: