<Teleport>

<Teleport> 组件将一个组件传送到 DOM 中的不同位置。
<Teleport>to 目标期望是一个 CSS 选择器字符串或一个实际的 DOM 节点。Nuxt 当前仅对 #teleports 的传送支持服务端渲染(SSR),对于其他目标在客户端支持需要使用 <ClientOnly> 包裹。

主体传送

<template>
  <button @click="open = true">
    打开模态框
  </button>
  <Teleport to="#teleports">
    <div v-if="open" class="modal">
      <p>来自模态框的问候!</p>
      <button @click="open = false">
        关闭
      </button>
    </div>
  </Teleport>
</template>

客户端传送

<template>
  <ClientOnly>
    <Teleport to="#some-selector">
      <!-- 内容 -->
    </Teleport>
  </ClientOnly>
</template>
Read and edit a live example in Docs > Examples > Advanced > Teleport.