mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-03 02:47:12 +00:00
35 lines
888 B
Markdown
35 lines
888 B
Markdown
|
# Teleports
|
||
|
|
||
|
Vue 3 provides the [`<Teleport>` component](https://vuejs.org/guide/built-ins/teleport.html) which allows content to be rendered elsewhere in the DOM, outside of the Vue application.
|
||
|
|
||
|
The `to` target of `<Teleport>` expects a CSS selector string or an actual DOM node. Nuxt currently has SSR support for teleports to `body` only, with client-side support for other targets using a `<ClientOnly>` wrapper.
|
||
|
|
||
|
## Example: body teleport
|
||
|
|
||
|
```vue
|
||
|
<template>
|
||
|
<button @click="open = true">
|
||
|
Open Modal
|
||
|
</button>
|
||
|
<Teleport to="body">
|
||
|
<div v-if="open" class="modal">
|
||
|
<p>Hello from the modal!</p>
|
||
|
<button @click="open = false">
|
||
|
Close
|
||
|
</button>
|
||
|
</div>
|
||
|
</Teleport>
|
||
|
</template>
|
||
|
```
|
||
|
|
||
|
## Example: client-side teleport
|
||
|
|
||
|
```vue
|
||
|
<ClientOnly>
|
||
|
<Teleport to="#some-selector">
|
||
|
<!-- content -->
|
||
|
</Teleport>
|
||
|
</ClientOnly>
|
||
|
</template>
|
||
|
```
|