Skip to content

Commit

Permalink
translate suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong2008 committed May 6, 2024
1 parent 84b80b4 commit 843afb6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/guide/built-ins/suspense.md
Expand Up @@ -133,9 +133,9 @@ const posts = await res.json()

Vue Router 使用动态导入对[懒加载组件](https://router.vuejs.org/zh/guide/advanced/lazy-loading.html)进行了内置支持。这些与异步组件不同,目前他们不会触发 `<Suspense>`。但是,它们仍然可以有异步组件作为后代,这些组件可以照常触发 `<Suspense>`

## Nested Suspense {#nested-suspense}
## 嵌套使用 {#nested-suspense}

<!-- TODO: translation -->When we have multiple async components (common for nested or layout-based routes) like this:
当我们有多个类似于下方的异步组件(常见于嵌套或基于布局的路由)时:

```vue-html
<Suspense>
Expand All @@ -145,9 +145,9 @@ Vue Router 使用动态导入对[懒加载组件](https://router.vuejs.org/zh/gu
</Suspense>
```

`<Suspense>` creates a boundary that will resolve all the async components down the tree, as expected. However, when we change `DynamicAsyncOuter`, `<Suspense>` awaits it correctly, but when we change `DynamicAsyncInner`, the nested `DynamicAsyncInner` renders an empty node until it has been resolved (instead of the previous one or fallback slot).
`<Suspense>`创建了一个边界,它将如预期的那样解析树下的所有异步组件。然而,当我们更改 `DynamicAsyncOuter` 时,`<Suspense>` 会正确地等待它,但当我们更改 `DynamicAsyncInner` 时,嵌套的 `DynamicAsyncInner` 会呈现为一个空节点,直到它被解析为止(而不是之前的节点或回退插槽)。

In order to solve that, we could have a nested suspense to handle the patch for the nested component, like:
为了解决这个问题,我们可以使用嵌套的方法来处理嵌套组件的补丁,就像这样:

```vue-html
<Suspense>
Expand All @@ -159,7 +159,7 @@ In order to solve that, we could have a nested suspense to handle the patch for
</Suspense>
```

If you don't set the `suspensible` prop, the inner `<Suspense>` will be treated like a sync component by the parent `<Suspense>`. That means that it has its own fallback slot and if both `Dynamic` components change at the same time, there might be empty nodes and multiple patching cycles while the child `<Suspense>` is loading its own dependency tree, which might not be desirable. When it's set, all the async dependency handling is given to the parent `<Suspense>` (including the events emitted) and the inner `<Suspense>` serves solely as another boundary for the dependency resolution and patching.
如果你不设置 `suspensible` 属性,内部的 `<Suspense>` 将被父级 `<Suspense>` 视为同步组件。这意味着它将会有自己的回退插槽,如果两个 `Dynamic` 组件同时被修改,则当子 `<Suspense>` 加载其自己的依赖关系树时,可能会出现空节点和多个修补周期,这可能不是理想情况。设置后,所有异步依赖项处理都会交给父级 `<Suspense>`(包括发出的事件),而内部 `<Suspense>` 仅充当依赖项解析和修补的另一个边界。

---

Expand Down

0 comments on commit 843afb6

Please sign in to comment.