0 day streak
javascript / beginner
Snippet

Moving DOM Elements with Teleport

The Teleport component allows you to render a part of a component's template into a DOM node that exists outside the component's own hierarchy, such as the end of the <body>.

snippet.js
javascript
1
2
3
4
5
<template>
<Teleport to="body">
<div class="modal">I am appended to the body tag!</div>
</Teleport>
</template>
vue
Breakdown
1
<Teleport to="body">
The 'to' attribute specifies the CSS selector of the target destination.