2026-01-19 23:45:08 +08:00
|
|
|
|
<!--
|
2026-02-23 01:50:43 +08:00
|
|
|
|
ApiQuickStartDemo.vue - 紧凑版
|
|
|
|
|
|
目标:展示最简单的 API 调用流程,一眼看懂
|
2026-01-19 23:45:08 +08:00
|
|
|
|
-->
|
|
|
|
|
|
<template>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="demo-root">
|
|
|
|
|
|
<div class="demo-header">
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<span class="icon">🌐</span>
|
|
|
|
|
|
<span class="title">试试看:获取当前时间</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="demo-layout">
|
|
|
|
|
|
<div class="left-panel">
|
|
|
|
|
|
<div class="terminal">
|
|
|
|
|
|
<div class="term-bar">
|
|
|
|
|
|
<span class="dot r" /><span class="dot y" /><span class="dot g" />
|
|
|
|
|
|
<span class="term-title">API 请求</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="term-body">
|
|
|
|
|
|
<div class="t-line">
|
|
|
|
|
|
<span class="t-ps">> </span>
|
|
|
|
|
|
<span class="t-cmd">GET /api/time</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="calling" class="t-line">
|
|
|
|
|
|
<span class="t-dim">请求中...</span>
|
|
|
|
|
|
<span class="t-loading">▋</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="result" class="t-line">
|
|
|
|
|
|
<span class="t-grn">HTTP/1.1 200 OK</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="result" class="t-line">
|
|
|
|
|
|
<span class="t-dim">{ "time": "{{ result.timeString }}" }</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button class="call-btn" :disabled="calling" @click="callApi">
|
|
|
|
|
|
{{ calling ? '请求中...' : '📡 发起请求' }}
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="right-panel">
|
|
|
|
|
|
<div class="flow-col" :class="{ 'flow-highlight': stage === 'client' }">
|
|
|
|
|
|
<div class="flow-header">
|
|
|
|
|
|
<span class="flow-icon">💻</span>
|
|
|
|
|
|
<span class="flow-title">客户端</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="flow-body">
|
|
|
|
|
|
{{ stage === 'client' ? '准备请求...' : '等待中' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flow-arrow" :class="{ 'arrow-lit': stage === 'request' }">
|
|
|
|
|
|
<span class="arrow-symbol">→</span>
|
|
|
|
|
|
<code class="arrow-label">Request</code>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flow-col" :class="{ 'flow-highlight': stage === 'server' }">
|
|
|
|
|
|
<div class="flow-header">
|
|
|
|
|
|
<span class="flow-icon">🖥️</span>
|
|
|
|
|
|
<span class="flow-title">服务器</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="flow-body">
|
|
|
|
|
|
{{ stage === 'server' ? '处理中...' : '等待中' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flow-arrow" :class="{ 'arrow-lit': stage === 'response' }">
|
|
|
|
|
|
<code class="arrow-label">Response</code>
|
|
|
|
|
|
<span class="arrow-symbol">←</span>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div
|
2026-02-23 01:50:43 +08:00
|
|
|
|
class="flow-col"
|
|
|
|
|
|
:class="{ 'flow-highlight': stage === 'response' }"
|
2026-02-18 17:38:10 +08:00
|
|
|
|
>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="flow-header">
|
|
|
|
|
|
<span class="flow-icon">📦</span>
|
|
|
|
|
|
<span class="flow-title">响应</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="flow-body">
|
|
|
|
|
|
<span v-if="result" class="result-time">{{
|
|
|
|
|
|
result.timeString
|
|
|
|
|
|
}}</span>
|
|
|
|
|
|
<span v-else>等待响应</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
</div>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
<div class="info-box">
|
|
|
|
|
|
<strong>核心思想:</strong>
|
2026-02-23 12:09:47 +08:00
|
|
|
|
<span>点击按钮 → 发送请求 → 服务器处理 → 返回数据。这就是 API
|
|
|
|
|
|
调用的完整流程。</span>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
import { ref } from 'vue'
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
const calling = ref(false)
|
2026-01-19 23:45:08 +08:00
|
|
|
|
const result = ref(null)
|
2026-02-23 01:50:43 +08:00
|
|
|
|
const stage = ref(null)
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
function callApi() {
|
|
|
|
|
|
calling.value = true
|
2026-01-19 23:45:08 +08:00
|
|
|
|
result.value = null
|
2026-02-23 01:50:43 +08:00
|
|
|
|
stage.value = 'client'
|
2026-01-19 23:45:08 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
stage.value = 'request'
|
|
|
|
|
|
}, 150)
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
stage.value = 'server'
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
stage.value = 'response'
|
|
|
|
|
|
}, 450)
|
2026-01-20 08:51:04 +08:00
|
|
|
|
setTimeout(() => {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
const now = new Date()
|
2026-01-19 23:45:08 +08:00
|
|
|
|
result.value = {
|
2026-02-23 01:50:43 +08:00
|
|
|
|
timeString: now.toLocaleString('zh-CN', {
|
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
|
second: '2-digit'
|
|
|
|
|
|
})
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-01-20 08:51:04 +08:00
|
|
|
|
calling.value = false
|
2026-02-23 01:50:43 +08:00
|
|
|
|
}, 500)
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.demo-root {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-23 01:50:43 +08:00
|
|
|
|
border-radius: 10px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
overflow: hidden;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
|
font-size: 0.85rem;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.demo-header {
|
|
|
|
|
|
padding: 10px 16px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
gap: 8px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.icon {
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 18px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.title {
|
|
|
|
|
|
font-weight: 600;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 0.9rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-layout {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: stretch;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.left-panel {
|
|
|
|
|
|
flex: 1;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
border-right: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.right-panel {
|
|
|
|
|
|
width: 200px;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 0;
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 640px) {
|
|
|
|
|
|
.demo-layout {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
.left-panel {
|
|
|
|
|
|
border-right: none;
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
.right-panel {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.flow-arrow {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.terminal {
|
|
|
|
|
|
background: #141420;
|
|
|
|
|
|
}
|
|
|
|
|
|
.term-bar {
|
|
|
|
|
|
display: flex;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
align-items: center;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
gap: 5px;
|
|
|
|
|
|
padding: 6px 10px;
|
|
|
|
|
|
background: #1e1e2e;
|
|
|
|
|
|
}
|
|
|
|
|
|
.dot {
|
|
|
|
|
|
width: 10px;
|
|
|
|
|
|
height: 10px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
|
|
|
|
|
.dot.r {
|
|
|
|
|
|
background: #ff5f57;
|
|
|
|
|
|
}
|
|
|
|
|
|
.dot.y {
|
|
|
|
|
|
background: #febc2e;
|
|
|
|
|
|
}
|
|
|
|
|
|
.dot.g {
|
|
|
|
|
|
background: #28c840;
|
|
|
|
|
|
}
|
|
|
|
|
|
.term-title {
|
|
|
|
|
|
margin-left: 6px;
|
|
|
|
|
|
font-size: 0.7rem;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.term-body {
|
|
|
|
|
|
min-height: 80px;
|
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
|
font-family: 'Menlo', 'Monaco', monospace;
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
|
color: #cdd6f4;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-line {
|
|
|
|
|
|
margin-bottom: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-ps {
|
|
|
|
|
|
color: #89b4fa;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-cmd {
|
|
|
|
|
|
color: #cdd6f4;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-dim {
|
|
|
|
|
|
color: #585b70;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-grn {
|
|
|
|
|
|
color: #a6e3a1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.t-loading {
|
|
|
|
|
|
animation: blink 1s step-end infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
@keyframes blink {
|
|
|
|
|
|
0%,
|
|
|
|
|
|
100% {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
50% {
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
}
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.call-btn {
|
2026-02-23 01:50:43 +08:00
|
|
|
|
margin: 10px;
|
|
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
|
background: var(--vp-c-brand);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
font-size: 0.85rem;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
font-weight: 600;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.call-btn:disabled {
|
2026-02-23 01:50:43 +08:00
|
|
|
|
opacity: 0.6;
|
|
|
|
|
|
cursor: not-allowed;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-col {
|
|
|
|
|
|
border: 1.5px solid var(--vp-c-divider);
|
2026-02-14 20:23:34 +08:00
|
|
|
|
border-radius: 6px;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
transition:
|
|
|
|
|
|
border-color 0.2s,
|
|
|
|
|
|
box-shadow 0.2s;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-col.flow-highlight {
|
|
|
|
|
|
border-color: var(--vp-c-brand);
|
|
|
|
|
|
box-shadow: 0 0 0 2px color-mix(in srgb, var(--vp-c-brand) 12%, transparent);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-header {
|
|
|
|
|
|
padding: 4px 8px;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 4px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-icon {
|
|
|
|
|
|
font-size: 0.8rem;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-title {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
font-weight: 600;
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 0.75rem;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-body {
|
|
|
|
|
|
padding: 6px 8px;
|
|
|
|
|
|
font-size: 0.72rem;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.result-time {
|
|
|
|
|
|
color: var(--vp-c-brand);
|
|
|
|
|
|
font-weight: 600;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-arrow {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
gap: 4px;
|
|
|
|
|
|
padding: 2px 0;
|
|
|
|
|
|
opacity: 0.3;
|
|
|
|
|
|
transition: opacity 0.2s;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.flow-arrow.arrow-lit {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.arrow-symbol {
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
color: var(--vp-c-brand);
|
|
|
|
|
|
}
|
|
|
|
|
|
.arrow-label {
|
|
|
|
|
|
font-size: 0.6rem;
|
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
|
color: var(--vp-c-brand);
|
2026-02-01 23:42:12 +08:00
|
|
|
|
}
|
2026-01-20 17:53:22 +08:00
|
|
|
|
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.info-box {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 0.25rem;
|
|
|
|
|
|
padding: 10px 14px;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
border-top: 1px solid var(--vp-c-divider);
|
2026-02-23 01:50:43 +08:00
|
|
|
|
font-size: 0.8rem;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
2026-02-23 01:50:43 +08:00
|
|
|
|
.info-box strong {
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
flex-shrink: 0;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|