Vue Nuxt
Tips & Tricks

A collection of Vue, Nuxt and Vite tips, tricks and good practices.

In Vue, you can "teleport" a part of a component's template into a DOM node that exists outside the DOM hierarchy of that component. To do this, use the built-in Teleport component and target the specific DOM element you want to teleport the part of your template to.

<template>
  <Teleport to="body">
    <div v-if="open" class="modal">
      <p>Hello from the modal!</p>
      <button @click="open = false">Close</button>
    </div>
  </Teleport>
  </template>