2026-01-19 23:45:08 +08:00
|
|
|
|
<!--
|
2026-01-20 17:53:22 +08:00
|
|
|
|
ApiQuickStartDemo.vue - 演示版
|
|
|
|
|
|
目标:展示最简单的 API 调用流程
|
2026-01-19 23:45:08 +08:00
|
|
|
|
-->
|
|
|
|
|
|
<template>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
<div class="demo">
|
2026-01-20 17:53:22 +08:00
|
|
|
|
<div class="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-01-20 17:53:22 +08:00
|
|
|
|
<div class="content">
|
|
|
|
|
|
<div class="action-area">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<button
|
|
|
|
|
|
class="call-btn"
|
|
|
|
|
|
:disabled="calling"
|
|
|
|
|
|
@click="callApi"
|
|
|
|
|
|
>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
<span v-if="!calling">📡 发起 API 请求</span>
|
|
|
|
|
|
<span v-else>🔄 请求处理中...</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="result || calling"
|
|
|
|
|
|
class="result-area"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="calling"
|
|
|
|
|
|
class="loading-dots"
|
|
|
|
|
|
>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
<span>.</span><span>.</span><span>.</span>
|
2026-01-19 23:45:08 +08:00
|
|
|
|
</div>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-else-if="result"
|
|
|
|
|
|
class="response-card"
|
|
|
|
|
|
>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
<div class="response-header">
|
|
|
|
|
|
<span class="status-badge success">200 OK</span>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<span class="time">耗时: {{ result.time }}ms</span>
|
2026-01-20 17:53:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="response-body">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div class="time-display">
|
|
|
|
|
|
{{ result.timeString }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="timezone">
|
|
|
|
|
|
{{ result.timezone }}
|
|
|
|
|
|
</div>
|
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-01-20 17:53:22 +08:00
|
|
|
|
<div class="footer">
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<p>
|
|
|
|
|
|
👆 <strong>流程演示:</strong> 点击按钮 -> 发送请求 -> 服务器处理 ->
|
|
|
|
|
|
返回数据。
|
|
|
|
|
|
</p>
|
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-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-01 23:42:12 +08:00
|
|
|
|
const startTime = Date.now()
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
setTimeout(() => {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
const now = new Date()
|
|
|
|
|
|
const timeString = now.toLocaleString('zh-CN', {
|
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
|
second: '2-digit'
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-01-19 23:45:08 +08:00
|
|
|
|
result.value = {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
time: Date.now() - startTime,
|
|
|
|
|
|
timeString: `🕐 ${timeString}`,
|
|
|
|
|
|
timezone: '亚洲/上海 (UTC+8)'
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
2026-01-20 08:51:04 +08:00
|
|
|
|
calling.value = false
|
2026-02-01 23:42:12 +08:00
|
|
|
|
}, 300 + Math.random() * 200)
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.demo {
|
2026-01-19 23:45:08 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
border-radius: 12px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
margin: 24px 0;
|
|
|
|
|
|
overflow: hidden;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.header {
|
|
|
|
|
|
padding: 16px 20px;
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.icon {
|
|
|
|
|
|
font-size: 24px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.title {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
|
padding: 24px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 20px;
|
|
|
|
|
|
min-height: 160px;
|
|
|
|
|
|
justify-content: center;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.call-btn {
|
2026-01-20 17:53:22 +08:00
|
|
|
|
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
2026-01-20 08:51:04 +08:00
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
padding: 12px 32px;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
font-size: 16px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
border-radius: 50px;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
cursor: pointer;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
|
|
|
|
box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.5);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.call-btn:hover:not(:disabled) {
|
2026-01-20 17:53:22 +08:00
|
|
|
|
transform: translateY(-2px);
|
|
|
|
|
|
box-shadow: 0 6px 8px -1px rgba(59, 130, 246, 0.6);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 08:51:04 +08:00
|
|
|
|
.call-btn:disabled {
|
2026-01-20 17:53:22 +08:00
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
cursor: wait;
|
|
|
|
|
|
transform: scale(0.98);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.result-area {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
max-width: 400px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.response-card {
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-14 20:23:34 +08:00
|
|
|
|
border-radius: 6px;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
padding: 16px;
|
|
|
|
|
|
animation: slideUp 0.3s ease-out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.response-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.status-badge {
|
2026-01-20 08:51:04 +08:00
|
|
|
|
background: #dcfce7;
|
|
|
|
|
|
color: #166534;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
padding: 2px 8px;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
font-weight: bold;
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.response-body {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.time-display {
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
font-weight: 600;
|
2026-01-20 17:53:22 +08:00
|
|
|
|
color: var(--vp-c-text-1);
|
2026-02-01 23:42:12 +08:00
|
|
|
|
margin-bottom: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.timezone {
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 17:53:22 +08:00
|
|
|
|
.loading-dots span {
|
|
|
|
|
|
animation: blink 1.4s infinite both;
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
margin: 0 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-01 23:42:12 +08:00
|
|
|
|
.loading-dots span:nth-child(2) {
|
|
|
|
|
|
animation-delay: 0.2s;
|
|
|
|
|
|
}
|
|
|
|
|
|
.loading-dots span:nth-child(3) {
|
|
|
|
|
|
animation-delay: 0.4s;
|
|
|
|
|
|
}
|
2026-01-20 17:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
|
|
padding: 12px 20px;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
background: rgba(0, 0, 0, 0.02);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
border-top: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
font-size: 13px;
|
2026-01-20 08:51:04 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-01-20 17:53:22 +08:00
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes slideUp {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
from {
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
transform: translateY(10px);
|
|
|
|
|
|
}
|
|
|
|
|
|
to {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
|
}
|
2026-01-20 17:53:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes blink {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
0% {
|
|
|
|
|
|
opacity: 0.2;
|
|
|
|
|
|
}
|
|
|
|
|
|
20% {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
100% {
|
|
|
|
|
|
opacity: 0.2;
|
|
|
|
|
|
}
|
2026-01-19 23:45:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|