Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Latest commit

 

History

History
37 lines (31 loc) · 960 Bytes

11.teleports.md

File metadata and controls

37 lines (31 loc) · 960 Bytes
title description
Teleports
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

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

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