update
This commit is contained in:
+26
-1
@@ -1,15 +1,34 @@
|
||||
// src/app.tsx
|
||||
|
||||
import { PostEntity } from '@3rapp/api/modules/content/entities/post.entity';
|
||||
import { StyleProvider } from '@ant-design/cssinjs';
|
||||
import { Button, ConfigProvider, theme, App as AntdApp } from 'antd';
|
||||
// import 'dayjs/locale/zh-cn';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
|
||||
import { FC } from 'react';
|
||||
import axios from 'axios';
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
|
||||
import $styles from './app.module.css';
|
||||
|
||||
const getPosts = async () => {
|
||||
let data: PostEntity[] = [];
|
||||
try {
|
||||
const res = await axios.get('/api/posts');
|
||||
data = res.data;
|
||||
} catch (err) {
|
||||
console.log('Error:', err);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
const App: FC = () => {
|
||||
const [data, setData] = useState<PostEntity[]>([]);
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setData(await getPosts());
|
||||
})();
|
||||
}, []);
|
||||
return (
|
||||
<ConfigProvider
|
||||
locale={zhCN}
|
||||
@@ -38,6 +57,12 @@ const App: FC = () => {
|
||||
>
|
||||
点此打开
|
||||
</Button>
|
||||
<h2>文章列表</h2>
|
||||
<ul>
|
||||
{data.map((item) => (
|
||||
<li key={item.id}>{item.title}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</AntdApp>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface Post {
|
||||
title: string;
|
||||
body: string;
|
||||
}
|
||||
Reference in New Issue
Block a user