-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n(zh-cn): translate guides/actions.mdx into Chinese(Simplified) #9439
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
||
使用 actions 而不是 API 端点,以实现客户端和服务器代码之间的无缝通信,并且可以: | ||
|
||
- 使用 [Zod 校验](https://zod.dev/?id=primitives)自动校验 JSON 和表单数据输入。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 使用 [Zod 校验](https://zod.dev/?id=primitives)自动校验 JSON 和表单数据输入。 | |
- 使用 [Zod 校验](https://zod.dev/README_ZH?id=原始类型)自动校验 JSON 和表单数据输入。 |
我把它更新成了官方的中文文档链接~
} | ||
``` | ||
|
||
3. 使用 `defineAction()` 工具定义一个 `getGreeting` action。`input` 属性将使用 [Zod](https://zod.dev) 模式验证输入参数,`handler()` 函数包含要在服务器上运行的后端逻辑。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. 使用 `defineAction()` 工具定义一个 `getGreeting` action。`input` 属性将使用 [Zod](https://zod.dev) 模式验证输入参数,`handler()` 函数包含要在服务器上运行的后端逻辑。 | |
3. 使用 `defineAction()` 工具定义一个 `getGreeting` action。`input` 属性将使用 [Zod](https://zod.dev/README_ZH) scheme 验证输入参数,`handler()` 函数包含要在服务器上运行的后端逻辑。 |
} | ||
``` | ||
|
||
然后,你可以将此 `user` 对象导入到你的 `src/actions/index.ts` 文件中,并将其添加为 `server` 对象中的顶级键,以及任何其他 actions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然后,你可以将此 `user` 对象导入到你的 `src/actions/index.ts` 文件中,并将其添加为 `server` 对象中的顶级键,以及任何其他 actions: | |
然后,你可以将此 `user` 对象导入到你的 `src/actions/index.ts` 文件中,并将其作为顶层键与任何其他 actions 一起添加到 `server` 对象中: |
|
||
## 处理返回的数据 | ||
|
||
Actions 返回一个对象,其中包含 `data`,它是 `handler()` 的具备类型安全的返回值,或者是一个 `error`,其中包含任何后端错误。错误可能来自 `input` 属性上的验证错误,或者来自 `handler()` 中抛出的错误。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions 返回一个对象,其中包含 `data`,它是 `handler()` 的具备类型安全的返回值,或者是一个 `error`,其中包含任何后端错误。错误可能来自 `input` 属性上的验证错误,或者来自 `handler()` 中抛出的错误。 | |
Actions 会返回一个对象,这个对象要么是具备 `handler()` 类型安全性的返回值 `data`,要么是包含着任何后端错误的 `error`。错误可能来自 `input` 属性上的验证错误,或者来自 `handler()` 中抛出的错误。 |
我把句中的 either...or...
语义加入并润色了一下。
|
||
```ts ins="orThrow" | ||
const updatedLikes = await actions.likePost.orThrow({ postId: 'example' }); | ||
// ^ type: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ^ type: number | |
// ^ 类型:number |
--- | ||
<form method="POST" action={actions.logout}> | ||
<button>Log out</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<button>Log out</button> | |
<button>退出登录</button> |
<form method="POST" action={'/confirmation' + actions.newsletter}> | ||
<label>E-mail <input required type="email" name="email" /></label> | ||
<button>Sign up</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<button>Sign up</button> | |
<button>注册</button> |
<p class="error">Unable to sign up. Please try again later.</p> | ||
)} | ||
<form method="POST" action={'/confirmation' + actions.newsletter}> | ||
<label> | ||
<input required type="email" name="email" /> | ||
</label> | ||
<button>Sign up</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p class="error">Unable to sign up. Please try again later.</p> | |
)} | |
<form method="POST" action={'/confirmation' + actions.newsletter}> | |
<label> | |
<input required type="email" name="email" /> | |
</label> | |
<button>Sign up</button> | |
<p class="error">无法注册。请稍后再试。</p> | |
)} | |
<form method="POST" action={'/confirmation' + actions.newsletter}> | |
<label> | |
<input required type="email" name="email" /> | |
</label> | |
<button>注册</button> |
<input required type="email" name="email" aria-describedby="error" /> | ||
</label> | ||
{inputErrors.email && <p id="error">{inputErrors.email.join(',')}</p>} | ||
<button>Sign up</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<button>Sign up</button> | |
<button>注册</button> |
--- | ||
{result && !result.error && ( | ||
<p class="success">Added {result.data.productName} to cart</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p class="success">Added {result.data.productName} to cart</p> | |
<p class="success">添加 {result.data.productName} 到购物车</p> |
Description (required)
Translate the
/en/guides/actions
into Chinese(Simplified).