---
title: "<Teleport>"
description: "<Teleport> 组件会将组件传送到 DOM 的其他位置。"
canonical_url: "https://nuxt.zhcndoc.com/docs/4.x/api/components/teleports"
---
# <Teleport>

> <Teleport> 组件会将组件传送到 DOM 的其他位置。

<warning>

[`<Teleport>`](https://vue.zhcndoc.com/guide/built-ins/teleport) 的 `to` 目标期望一个 CSS 选择器字符串或一个实际的 DOM 节点。Nuxt 目前仅对传送到 `#teleports` 的情况提供 SSR 支持，其他目标的客户端支持需使用 `<ClientOnly>` 包裹。

</warning>

## 页面主体传送

```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/4.x/examples/advanced/teleport">



</link-example>


## Sitemap

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