Nuxt/docs/3.api/2.components/8.teleports.md
Sébastien Chopin 3ec108493d
docs: simplify the docs directory (#18506)
* docs: simplify docs to only markdown

* Create nuxt-config.md

* chore: update

* chore: add readme
2023-01-25 10:41:41 +01:00

1015 B

description
The <Teleport> component teleports a component to a different location in the DOM.

<Teleport>

The <Teleport> component teleports a component to a different location in the DOM.

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="/docs/examples/app/teleport"} ::