Skip to content

Commit 444c780

Browse files
committed
3.5: deferred teleport
1 parent b6339b6 commit 444c780

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/api/built-in-components.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ Renders its slot content to another part of the DOM.
286286
* Can be changed dynamically.
287287
*/
288288
disabled?: boolean
289+
/**
290+
* When `true`, the Teleport will defer until other
291+
* parts of the application have been mounted before
292+
* resolving its target. (3.5+)
293+
*/
294+
defer?: boolean
289295
}
290296
```
291297

@@ -307,6 +313,15 @@ Renders its slot content to another part of the DOM.
307313
</Teleport>
308314
```
309315

316+
Defer target resolution <sup class="vt-badge" data-text="3.5+" />:
317+
318+
```vue-html
319+
<Teleport defer to="#late-div">...</Teleport>
320+
321+
<!-- somewhere later in the template -->
322+
<div id="late-div"></div>
323+
```
324+
310325
- **See also** [Guide - Teleport](/guide/built-ins/teleport)
311326

312327
## `<Suspense>` <sup class="vt-badge experimental" /> {#suspense}

src/guide/built-ins/teleport.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ The rendered result would be:
195195
</div>
196196
```
197197

198+
## Deferred Teleport <sup class="vt-badge" data-text="3.5+" /> {#deferred-teleport}
199+
200+
In Vue 3.5 and above, we can use the `defer` prop to defer the target resolving of a Teleport until other parts of the application have mounted. This allows the Teleport to target a container element that is rendered by Vue, but in a later part of the component tree:
201+
202+
```vue-html
203+
<Teleport defer to="#late-div">...</Teleport>
204+
205+
<!-- somewhere later in the template -->
206+
<div id="late-div"></div>
207+
```
208+
209+
Note that the target element must be rendered in the same mount / update tick with the Teleport - i.e. if the `<div>` is only mounted a second later, the Teleport will still report an error. The defer works similarly to the `mounted` lifecycle hook.
210+
198211
---
199212

200213
**Related**

0 commit comments

Comments
 (0)