-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
39 lines (36 loc) · 965 Bytes
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
import {GetServerSideProps, NextPage} from "next";
import {getDatabaseConnection} from '../lib/getDatabaseConnection';
console.log('执行了 index.tsx')
import {Post} from '../src/entity/Post';
import Link from 'next/link';
type Props = {
posts: Post[];
}
const index: NextPage<Props> = (props) => {
const {posts} = props;
return (
<>
<div>
<h1>文章列表</h1>
{posts.map(post =>
<Link key={post.id} href={`/posts/${post.id}`}>
<a>
{post.title}
</a>
</Link>
)}
</div>
</>
)
}
export default index;
export const getServerSideProps:GetServerSideProps = async (context)=>{
const connection = await getDatabaseConnection()// 第一次链接能不能用 get
const posts = await connection.manager.find(Post)
return {
props: {
posts:JSON.parse(JSON.stringify(posts))
}
}
}