Vue Universal Modal

1.1.4 · active · verified Sun Apr 19

Vue Universal Modal is a lightweight and simple modal plugin specifically designed for Vue 3 applications, leveraging Vue's built-in `teleport` feature. Currently at version 1.1.4, its release cadence appears to be relatively infrequent, with updates primarily focusing on bug fixes and dependency bumps since its last feature addition in v1.1.0 in April 2021. Key differentiators include its reliance on `teleport` for efficient DOM management, built-in accessibility (A11Y) features, and support for Server-Side Rendering (SSR) by requiring a pre-defined teleport target in the HTML. It provides essential modal functionalities like add/remove, visibility control, transitions, and automatic keyboard/mouse binding for closing, making it a robust solution for managing modals in modern Vue applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `vue-universal-modal` as a Vue 3 plugin and integrate a basic modal into a component using `v-model` for visibility control.

import { createApp, ref, defineComponent } from 'vue';
import VueUniversalModal from 'vue-universal-modal';
import 'vue-universal-modal/dist/index.css';

// Assuming you have an index.html with <div id="app"></div> and <div id="modals"></div>
const app = createApp({
  template: `
    <p>
      <button @click="showModal">Show modal</button>
    </p>
    <Modal v-model="isShow" :close="closeModal">
      <div class="modal-content">
        <p>Hello from Universal Modal!</p>
        <button @click="closeModal">Close Modal</button>
      </div>
    </Modal>
  `,
  setup() {
    const isShow = ref(false);

    function showModal() {
      isShow.value = true;
    }

    function closeModal() {
      isShow.value = false;
    }

    return {
      isShow,
      showModal,
      closeModal,
    };
  },
});

app.use(VueUniversalModal, {
  teleportTarget: '#modals',
  modalComponent: 'Modal', // Default, explicitly set for clarity
});

app.mount('#app');

// Basic CSS for demonstration (include in your main CSS or style block)
// .modal-content {
//   width: 300px;
//   padding: 30px;
//   box-sizing: border-box;
//   background-color: #fff;
//   font-size: 20px;
//   text-align: center;
// }

view raw JSON →