✨Feat: 增加 Card 组件
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { Button } from '@heroui/react';
|
||||
import Card from "./components/Card"
|
||||
|
||||
|
||||
function App() {
|
||||
|
||||
return (
|
||||
<> <Button>
|
||||
My Button
|
||||
</Button></>
|
||||
<><Card /></>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import {ScrollShadow} from "@heroui/react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function Card() {
|
||||
// Data
|
||||
const [data, setData] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
// Load Data
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await fetch('http://localhost:8080/agent/card/你好')
|
||||
if (!response.ok) {
|
||||
throw new Error('API Error');
|
||||
}
|
||||
const result = await response.json();
|
||||
setData(result);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch data: ", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
|
||||
return (
|
||||
<div className="w-full p-0 sm:max-w-sm">
|
||||
<ScrollShadow className="max-h-[500px] p-10">
|
||||
<div className="space-y-4">
|
||||
{loading ? (
|
||||
// 3. 加载状态显示 Loading...
|
||||
<p className="text-center text-gray-500">Loading data...</p>
|
||||
) : (
|
||||
// 4. 渲染从 API 获取的数据
|
||||
<pre>{data?.message}</pre>
|
||||
)}
|
||||
</div>
|
||||
</ScrollShadow>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
@import "tailwindcss/theme" theme(reference);
|
||||
@import "tailwindcss/theme";
|
||||
@import "@heroui/styles";
|
||||
Reference in New Issue
Block a user