<Teleport>
<Teleport> コンポーネントは、コンポーネントを DOM の異なる場所にテレポートします。
<Teleport>
の to
ターゲットは、CSS セレクタ文字列または実際の DOM ノードを期待します。Nuxt は現在、#teleports
へのテレポートのみ SSR をサポートしており、他のターゲットへのクライアントサイドのサポートは <ClientOnly>
ラッパーを使用します。
ボディテレポート
<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>
クライアントサイドテレポート
<template>
<ClientOnly>
<Teleport to="#some-selector">
<!-- content -->
</Teleport>
</ClientOnly>
</template>
サンプルコードの編集とプレビューexamples > advanced > teleport
※このページは Nuxt.js 公式ドキュメントの翻訳ページ(非公式)です。
公式ドキュメントの該当ページはこちら:
https://nuxt.com/docs/3.x/api/components/teleports