You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/components/async.md
+99Lines changed: 99 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,105 @@ If a loading component is provided, it will be displayed first while the inner c
108
108
109
109
If an error component is provided, it will be displayed when the Promise returned by the loader function is rejected. You can also specify a timeout to show the error component when the request is taking too long.
> This section only applies if you are using [Server-Side Rendering](/guide/scaling-up/ssr).
114
+
115
+
In Vue 3.5+, async components can control when they are hydrated by providing a hydration strategy.
116
+
117
+
- Vue provides a number of built-in hydration strategies. These built-in strategies need to be individually imported so they can be tree-shaken if not used.
118
+
119
+
- The design is intentionally low-level for flexibility. Compiler syntax sugar can potentially be built on top of this in the future either in core or in higher level solutions (e.g. Nuxt).
Hydrates when specified event(s) are triggered on the component element(s). The event that triggered the hydration will also be replayed once hydration is complete.
// forEachElement is a helper to iterate through all the root elememts
192
+
// in the component's non-hydrated DOM, since the root can be a fragment
193
+
// instead of a single element
194
+
forEachElement(el=> {
195
+
// ...
196
+
})
197
+
// call `hydrate` when ready
198
+
hydrate()
199
+
return () => {
200
+
// return a teardown function if needed
201
+
}
202
+
}
203
+
204
+
const AsyncComp =defineAsyncComponent({
205
+
loader: () =>import('./Comp.vue'),
206
+
hydrate: myStrategy
207
+
})
208
+
```
209
+
111
210
## Using with Suspense {#using-with-suspense}
112
211
113
212
Async components can be used with the `<Suspense>` built-in component. The interaction between `<Suspense>` and async components is documented in the [dedicated chapter for `<Suspense>`](/guide/built-ins/suspense).
0 commit comments