to 的目标<Teleport>需要一个 CSS 选择器字符串或一个实际的 DOM 节点。Nuxt 目前仅支持将传送到 #teleports 的 SSR,而对于其他目标,则通过 <ClientOnly> 包装器提供客户端支持。<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>