Files
test-repo/docs/.vitepress/theme/components/appendix/api-intro/ApiDocumentDemo.vue
T

195 lines
3.7 KiB
Vue
Raw Normal View History

2026-01-19 23:45:08 +08:00
<!--
ApiDocumentDemo.vue - 简化版
目标用简单的示例展示如何阅读 API 文档
2026-01-19 23:45:08 +08:00
-->
<template>
<div class="demo">
<div class="title">📖 怎么读 API 文档</div>
<p class="subtitle">找到这 3 个信息就够了</p>
<div class="doc-example">
<div class="doc-header">API 文档示例</div>
<div class="doc-body">
<div class="section">
<div class="section-title">📍 1 入口在哪</div>
<div class="section-content">
<code>GET /api/users/{id}</code>
<p class="hint">这就是你要调用的"按钮"</p>
</div>
2026-01-19 23:45:08 +08:00
</div>
<div class="section">
<div class="section-title">📝 2 要填什么</div>
<div class="section-content">
<div class="param">
<span class="param-name">id</span>
<span class="param-desc">用户编号必填</span>
2026-01-19 23:45:08 +08:00
</div>
<p class="hint">你需要提供这个参数</p>
2026-01-19 23:45:08 +08:00
</div>
</div>
<div class="section">
<div class="section-title"> 3 会得到什么</div>
<div class="section-content">
<pre><code>{
"id": "123",
"name": "张三",
"email": "zhang@example.com"
}</code></pre>
<p class="hint">成功时返回的数据格式</p>
2026-01-19 23:45:08 +08:00
</div>
</div>
</div>
</div>
<div class="tips">
<p><strong>💡 小贴士</strong></p>
<ul>
<li>先确认这个 API 是不是你需要的</li>
<li>再看要填什么参数必填 vs 可选</li>
<li>最后看返回什么失败会怎样</li>
</ul>
</div>
2026-01-19 23:45:08 +08:00
</div>
</template>
<script setup>
// 无需脚本逻辑
2026-01-19 23:45:08 +08:00
</script>
<style scoped>
.demo {
2026-01-19 23:45:08 +08:00
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
padding: 20px;
2026-01-19 23:45:08 +08:00
background: var(--vp-c-bg-soft);
margin: 16px 0;
2026-01-19 23:45:08 +08:00
}
.title {
font-size: 18px;
font-weight: bold;
margin-bottom: 8px;
2026-01-19 23:45:08 +08:00
color: var(--vp-c-text-1);
}
.subtitle {
2026-01-19 23:45:08 +08:00
color: var(--vp-c-text-2);
margin-bottom: 16px;
2026-01-19 23:45:08 +08:00
}
.doc-example {
2026-01-19 23:45:08 +08:00
background: var(--vp-c-bg);
border: 2px solid var(--vp-c-divider);
border-radius: 12px;
2026-01-19 23:45:08 +08:00
overflow: hidden;
margin-bottom: 16px;
2026-01-19 23:45:08 +08:00
}
.doc-header {
2026-01-19 23:45:08 +08:00
background: var(--vp-c-bg-soft);
padding: 12px 16px;
font-weight: bold;
font-size: 14px;
border-bottom: 1px solid var(--vp-c-divider);
2026-01-19 23:45:08 +08:00
}
.doc-body {
padding: 16px;
2026-01-19 23:45:08 +08:00
}
.section {
margin-bottom: 16px;
2026-01-19 23:45:08 +08:00
padding: 12px;
background: var(--vp-c-bg-soft);
border-radius: 8px;
2026-01-19 23:45:08 +08:00
}
.section:last-child {
margin-bottom: 0;
2026-01-19 23:45:08 +08:00
}
.section-title {
font-weight: bold;
2026-01-19 23:45:08 +08:00
font-size: 14px;
margin-bottom: 8px;
2026-01-19 23:45:08 +08:00
color: var(--vp-c-text-1);
}
.section-content {
margin-left: 0;
2026-01-19 23:45:08 +08:00
}
code {
background: #1e293b;
color: #e2e8f0;
padding: 4px 8px;
border-radius: 4px;
font-family: 'Monaco', 'Menlo', monospace;
2026-01-19 23:45:08 +08:00
font-size: 13px;
}
.hint {
2026-01-19 23:45:08 +08:00
margin-top: 8px;
font-size: 12px;
color: var(--vp-c-text-2);
font-style: italic;
2026-01-19 23:45:08 +08:00
}
.param {
2026-01-19 23:45:08 +08:00
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
2026-01-19 23:45:08 +08:00
}
.param-name {
background: #dbeafe;
color: #1e40af;
padding: 4px 8px;
border-radius: 4px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 12px;
font-weight: bold;
2026-01-19 23:45:08 +08:00
}
.param-desc {
font-size: 13px;
2026-01-19 23:45:08 +08:00
color: var(--vp-c-text-1);
}
pre {
background: #1e293b;
border-radius: 6px;
padding: 12px;
overflow-x: auto;
margin: 8px 0;
2026-01-19 23:45:08 +08:00
}
pre code {
background: transparent;
padding: 0;
color: #e2e8f0;
font-size: 12px;
line-height: 1.5;
2026-01-19 23:45:08 +08:00
}
.tips {
background: var(--vp-c-bg);
padding: 16px;
border-radius: 8px;
font-size: 14px;
2026-01-19 23:45:08 +08:00
line-height: 1.6;
color: var(--vp-c-text-2);
}
.tips ul {
margin: 8px 0 0 20px;
2026-01-19 23:45:08 +08:00
}
.tips li {
margin: 4px 0;
2026-01-19 23:45:08 +08:00
}
</style>