---
title: "<Teleport>"
description: "<Teleport> 组件可以将组件传送到 DOM 中的不同位置。"
canonical_url: "https://nuxt.zhcndoc.com/docs/3.x/api/components/teleports"
---
# \<Teleport>

> \<Teleport> 组件可以将组件传送到 DOM 中的不同位置。

::warning
[`<Teleport>`](https://vue.zhcndoc.com/guide/built-ins/teleport.html) 的 `to` 目标期望是一个 CSS 选择器字符串或一个实际的 DOM 节点。Nuxt 当前仅支持服务端渲染（SSR）将 teleport 发送到 `#teleports`，对于其他目标则需使用 `<ClientOnly>` 包裹实现客户端支持。
::

## 主体传送

```vue
<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>
```

## 客户端传送

```vue
<template>
  <ClientOnly>
    <Teleport to="#some-selector">
      <!-- 内容 -->
    </Teleport>
  </ClientOnly>
</template>
```

::link-example{to="https://nuxt.zhcndoc.com/docs/examples/advanced/teleport"}
::


## Sitemap

See the full [sitemap](https://nuxt.zhcndoc.com/sitemap.md) for all pages.
