<Teleport>

<Teleport> 组件将一个组件传送到 DOM 中的不同位置。
to 的目标<Teleport>需要一个 CSS 选择器字符串或一个实际的 DOM 节点。Nuxt 目前仅支持将传送到 #teleports 的 SSR,而对于其他目标,则通过 <ClientOnly> 包装器提供客户端支持。

Body Teleport

<template>
  <button @click="open = true">
    Open Modal
  </button>
  <Teleport to="#teleports">
    <div
      v-if="open"
      class="modal"
    >
      <p>Hello from the modal!</p>
      <button @click="open = false">
        Close
      </button>
    </div>
  </Teleport>
</template>

客户端 Teleport

<template>
  <ClientOnly>
    <Teleport to="#some-selector">
      <!-- content -->
    </Teleport>
  </ClientOnly>
</template>
Docs > 4 X > Examples > Advanced > Teleport 中阅读并编辑实时示例。