File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- title : openapi-fetch Examples
2
+ title : openapi-fetch 示例
3
3
---
4
4
5
- # Examples
5
+ # 示例
6
6
7
- ::: warning
7
+ 使用 openapi-fetch 与其他框架和库的示例代码。
8
8
9
- This article is a stub. Please help [ expand it ] ( https://github.com/drwpow/openapi-typescript/tree/main/docs/zh/ ) !
9
+ ## React + React Query
10
10
11
- :::
11
+ [ React Query] ( https://tanstack.com/query/latest ) 是在 React 中完美封装 openapi-fetch 的工具。仅有 13 kB 的大小,提供了客户端缓存而没有太多的客户端负担。其出色的类型推断通过最小的设置完美地保留了 openapi-fetch 的类型。
12
+
13
+ [ 在 GitHub 中查看代码示例] ( https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch/examples/react-query )
14
+
15
+ ## Next.js
16
+
17
+ [ Next.js] ( https://nextjs.org/ ) 是 React 的最流行的 SSR 框架。虽然对于所有客户端获取 openapi-fetch,推荐使用 [ React Query] ( #react--react-query ) (而不是 SWR),但该示例展示了如何利用 Next.js 的[ 服务器端获取] ( https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-fetch ) 并内建缓存。
18
+
19
+ [ 在 GitHub 中查看代码示例] ( https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch/examples/nextjs )
20
+
21
+ ## Svelte / SvelteKit
22
+
23
+ [ SvelteKit] ( https://kit.svelte.dev ) 的自动类型推断可以轻松地在客户端获取和 [ Page Data] ( https://kit.svelte.dev/docs/load#page-data ) 获取中捕获 openapi-fetch 的类型。而且它不需要任何额外的库。SvelteKit 还建议使用它们的[ 自定义 fetch] ( https://kit.svelte.dev/docs/load#making-fetch-requests ) 在 load 函数中工作。这可以通过 [ fetch options] ( /openapi-fetch/api#fetch-options ) 实现。
24
+
25
+ _ 注意:如果你在没有 SvelteKit 的情况下使用 Svelte,` src/routes/+page.svelte ` 中的根示例不使用任何 SvelteKit 特性,通常适用于任何设置。_
26
+
27
+ [ 在 GitHub 中查看代码示例] ( https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch/examples/sveltekit )
28
+
29
+ ## Vue
30
+
31
+ 目前还没有 Vue 的示例应用。你在 Vue 中使用吗?请[ 提交 PR 添加!] ( https://github.com/drwpow/openapi-typescript/pulls )
32
+
33
+ ---
34
+
35
+ 欢迎提供更多示例!请[ 提交 PR] ( https://github.com/drwpow/openapi-typescript/pulls ) 添加你的示例。
You can’t perform that action at this time.
0 commit comments