<Teleport>
<Teleport> 组件用于将组件传送到 DOM 中的其他位置。
<Teleport> 的 to 目标需要 CSS 选择器字符串或实际的 DOM 节点。Nuxt 目前仅支持将服务器端渲染到 #teleports 的端口,其他目标则使用 <ClientOnly> 封装器提供客户端支持。¥The to target of <Teleport> expects a CSS selector string or an actual DOM node. Nuxt currently has SSR support for teleports to #teleports only, with client-side support for other targets using a <ClientOnly> wrapper.Body 传送
¥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
¥Client-side Teleport
<template>
<ClientOnly>
<Teleport to="#some-selector">
<!-- content -->
</Teleport>
</ClientOnly>
</template>
Read and edit a live example in Docs > Examples > Advanced > Teleport.