Next.js
Next.js Server Actions 实战:零 API 路由实现全栈表单提交与数据变更
Waitwalker2026-08-2814 min
## 1. 极简 Server Action 范式
```tsx
// app/actions.ts
'use server'
import { revalidatePath } from 'next/cache';
export async function createPost(formData: FormData) {
const title = formData.get('title') as string;
await db.post.create({ data: { title } });
revalidatePath('/posts'); // 触发数据缓存失效与即时刷新
}
```
#Next.js#Server Actions#React 19#全栈
回到文章列表 →