Nuxt/docs/content/3.api/2.components/7.teleports.md
Clément Ollivier 944bba97ca
docs: update structure (#7047)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
2022-09-13 14:54:31 +02:00

949 B

<Teleport>

Vue 3 provides the <Teleport> component 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

<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

<template>
  <ClientOnly>
    <Teleport to="#some-selector">
      <!-- content -->
    </Teleport>
  </ClientOnly>
</template>

:LinkExample{link="/examples/app/teleport"}