diff --git a/src/api/options-lifecycle.md b/src/api/options-lifecycle.md index 9aa9c86a9..8fde60a63 100644 --- a/src/api/options-lifecycle.md +++ b/src/api/options-lifecycle.md @@ -214,12 +214,12 @@ - 如果 `errorCaptured` 钩子本身抛出了一个错误,那么这个错误和原来捕获到的错误都将被发送到 `app.config.errorHandler`。 - `errorCaptured` 钩子可以通过返回 `false` 来阻止错误继续向上传递。即表示“这个错误已经被处理了,应当被忽略”,它将阻止其他的 `errorCaptured` 钩子或 `app.config.errorHandler` 因这个错误而被调用。 - - **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. - - Replacing errored child component in parent component deep inside `` 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()`(永远会先抛出错误)和失败的渲染过程中的错误。 + + - 在 `` 的父组件中替换出错的子组件会导致 SSR 的激活不匹配。相反,尽量将可能抛出错误的逻辑从子组件的 `setup()` 中抽成一个独立的函数并在父组件的 `setup()` 中执行,这样就可以安全地 `try/catch` 执行过程,并在渲染实际的子组件前根据需要进行替换。 ## renderTracked {#rendertracked} diff --git a/src/guide/extras/render-function.md b/src/guide/extras/render-function.md index eb4253714..35c4434de 100644 --- a/src/guide/extras/render-function.md +++ b/src/guide/extras/render-function.md @@ -705,8 +705,8 @@ const vnode = withDirectives(h('div'), [ ### 模板引用 {#template-refs}
- -With the Composition API, when using [`useTemplateRef()`](/api/composition-api-helpers#usetemplateref) template refs are created by passing the string value as prop to the vnode: + +在组合式 API 中使用 [`useTemplateRef()`](/api/composition-api-helpers#usetemplateref) 时,模板引用是通过将字符串值作为 prop 传递给 vnode 创建的: ```js import { h, useTemplateRef } from 'vue' @@ -722,9 +722,9 @@ export default { ```
-Usage before 3.5 +3.5 之前的用法 -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'