full screen modal in vuejs v3 in javascript

To create a full-screen modal in Vue.js v3, you can use the built-in teleport option to append the modal to the body element of the DOM, making it appear on top of everything else. Here's an example of how to do it:

<template>
  <div>
    <button @click="showModal = true">Open Modal</button>
    <teleport to="body">
      <div v-if="showModal" class="modal">
        <div class="modal-content">
          <span class="close" @click="showModal = false">&times;</span>
          <h2>Modal Title</h2>
          <p>Modal content goes here.</p>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showModal: false
    }
  }
}
</script>

<style>
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 30px;
  font-weight: bold;
  color: gray;
  cursor: pointer;
}
</style>
977 chars
57 lines

Here, we're using a button to trigger the showModal data property whenever it's clicked. When showModal is set to true, the modal component is rendered and teleported to the body element using the teleport option.

The modal contains a close button (&times;) that sets the showModal property to false. The modal is styled using CSS to appear full-screen while staying centered in the middle of the viewport.

gistlibby LogSnag