nuxt logo

ドキュメント翻訳(非公式)

Nuxt.js
Version:v3.17

<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