<Teleport>
<Teleport>
組件將組件傳送至 DOM 中不同的位置。<Teleport>
的 to
目標需要 CSS 選擇器字串或實際的 DOM 節點。Nuxt 目前僅支援伺服器端渲染 (SSR) 將傳送目標設為 #teleports
,而對於其他目標的用戶端支援則需使用 <ClientOnly>
包裹器。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
<template>
<ClientOnly>
<Teleport to="#some-selector">
<!-- content -->
</Teleport>
</ClientOnly>
</template>
在 文件 > 範例 > 進階 > Teleport 中閱讀並編輯 live example。