Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/api/options-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@
- 如果 `errorCaptured` 钩子本身抛出了一个错误,那么这个错误和原来捕获到的错误都将被发送到 `app.config.errorHandler`。

- `errorCaptured` 钩子可以通过返回 `false` 来阻止错误继续向上传递。即表示“这个错误已经被处理了,应当被忽略”,它将阻止其他的 `errorCaptured` 钩子或 `app.config.errorHandler` 因这个错误而被调用。
<!-- TODO: translation -->
**Error Capturing Caveats**

- In components with async `setup()` function (with top-level `await`) Vue **will always** try to render component template, even if `setup()` throwed error. This will likely cause more errors because during render component's template might try to access non-existing properties of failed `setup()` context. When capturing errors in such components, be ready to handle errors from both failed async `setup()` (they will always come first) and failed render process.

- <sup class="vt-badge" data-text="SSR only"></sup> Replacing errored child component in parent component deep inside `<Suspense>` will cause hydration mismatches in SSR. Instead, try to separate logic that can possibly throw from child `setup()` into separate function and execute it in the parent component's `setup()`, where you can safely `try/catch` the execution process and make replacement if needed before rendering the actual child component.
**错误捕获注意事项**

- 在使用异步 `setup()` 函数(使用了顶层 `await`)的组件中,即使 `setup()` 抛出了错误,Vue 也会尝试渲染组件模板。这可能会导致更多错误,因为在渲染组件模板时,可能会尝试访问失败的 `setup()` 上下文中不存在的属性。当捕获这类组件的错误时,应当同时准备好捕获异步 `setup()`(永远会先抛出错误)和失败的渲染过程中的错误。

- <sup class="vt-badge" data-text="SSR only"></sup> 在 `<Suspense>` 的父组件中替换出错的子组件会导致 SSR 的激活不匹配。相反,尽量将可能抛出错误的逻辑从子组件的 `setup()` 中抽成一个独立的函数并在父组件的 `setup()` 中执行,这样就可以安全地 `try/catch` 执行过程,并在渲染实际的子组件前根据需要进行替换。

## renderTracked <sup class="vt-badge dev-only" /> {#rendertracked}

Expand Down
8 changes: 4 additions & 4 deletions src/guide/extras/render-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ const vnode = withDirectives(h('div'), [
### 模板引用 {#template-refs}

<div class="composition-api">
<!-- TODO: translation -->
With the Composition API, when using [`useTemplateRef()`](/api/composition-api-helpers#usetemplateref) <sup class="vt-badge" data-text="3.5+" /> template refs are created by passing the string value as prop to the vnode:

在组合式 API 中使用 [`useTemplateRef()`](/api/composition-api-helpers#usetemplateref) <sup class="vt-badge" data-text="3.5+" /> 时,模板引用是通过将字符串值作为 prop 传递给 vnode 创建的:

```js
import { h, useTemplateRef } from 'vue'
Expand All @@ -722,9 +722,9 @@ export default {
```

<details>
<summary>Usage before 3.5</summary>
<summary>3.5 之前的用法</summary>

In versions before 3.5 where useTemplateRef() was not introduced, template refs are created by passing the ref() itself as a prop to the vnode:
3.5 版本之前 useTemplateRef() 暂未引入,模板引用是通过将 ref() 本身作为 prop 传递给 vnode 创建的:

```js
import { h, ref } from 'vue'
Expand Down
Loading