<Teleport>
<Teleport> 组件可将组件传送到 DOM 中的不同位置。
<Teleport> 的 to 目标需要一个 CSS 选择器字符串或实际的 DOM 节点。Nuxt 目前仅支持对传送到 #teleports 的内容进行服务端渲染(SSR),对于其他目标则需要使用 <ClientOnly> 包装器提供客户端支持。Body 传送门
<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>
客户端传送门
<template>
<ClientOnly>
<Teleport to="#some-selector">
<!-- content -->
</Teleport>
</ClientOnly>
</template>
在 文档 > 4 X > 示例 > 进阶 > Teleport 中阅读并编辑在线示例。