Skip to content

Modal

A modal dialog component for displaying important information or forms.

Basic Usage

vue
<script setup>
import { ref } from 'vue'
const visible = ref(false)
</script>

<template>
  <MButton @click="visible = true">Open Modal</MButton>
  
  <MModal v-model="visible" title="Modal Title">
    <p>This is the modal content.</p>
  </MModal>
</template>

Sizes

vue
<template>
  <MModal v-model="visible" title="Small Modal" size="small">
    <p>Small modal content</p>
  </MModal>
  
  <MModal v-model="visible" title="Large Modal" size="large">
    <p>Large modal content</p>
  </MModal>
  
  <MModal v-model="visible" title="Full Modal" size="full">
    <p>Full size modal content</p>
  </MModal>
</template>

Custom Width

vue
<template>
  <MModal v-model="visible" title="Custom Width" custom-width="600px">
    <p>Modal with custom width</p>
  </MModal>
</template>
vue
<template>
  <MModal v-model="visible" title="Custom Footer">
    <p>Modal content</p>
    
    <template #footer>
      <MButton @click="visible = false">Cancel</MButton>
      <MButton type="primary" @click="handleSave">Save</MButton>
      <MButton type="danger" @click="handleDelete">Delete</MButton>
    </template>
  </MModal>
</template>
vue
<template>
  <MModal v-model="visible" title="No Footer" :show-footer="false">
    <p>Modal without footer buttons</p>
  </MModal>
</template>

Confirmation Dialog

vue
<script setup>
const handleConfirm = () => {
  console.log('Confirmed!')
  visible.value = false
}
</script>

<template>
  <MModal 
    v-model="visible" 
    title="Confirm Action"
    @confirm="handleConfirm"
  >
    <p>Are you sure you want to proceed?</p>
  </MModal>
</template>

Props

NameTypeDefaultDescription
modelValueboolean-Modal visibility (v-model)
titlestring''Modal title
size'small' | 'medium' | 'large' | 'full''medium'Modal size
customWidthstring-Custom max-width
showClosebooleantrueShow close button
showFooterbooleantrueShow footer area
showCancelbooleantrueShow cancel button
showConfirmbooleantrueShow confirm button
cancelTextstring'取消'Cancel button text
confirmTextstring'确定'Confirm button text
confirmDisabledbooleanfalseDisable confirm button
closeOnClickModalbooleantrueClose when clicking overlay
closeOnPressEscapebooleantrueClose when pressing Escape
contentClassstring''Custom class for content area

Events

NameParametersDescription
update:modelValue(value: boolean)Triggered when visibility changes
confirm-Triggered when confirm button is clicked
cancel-Triggered when modal is cancelled
open-Triggered when modal opens
close-Triggered when modal closes

Slots

NameDescription
defaultModal body content
headerCustom header content
footerCustom footer content

Released under the MIT License.