Skip to content

Modal

Modal dialog that displays content in an overlay, guiding users through related actions.

Basic Usage

Control visibility with v-model. Default layout includes title, content area, confirm and cancel buttons.

vue
<template>
  <ABtn @click="show = true">Open Modal</ABtn>
  <AModal v-model="show" title="Notification">
    This is the modal content area.
  </AModal>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const show = ref(false)
</script>

Custom Width

Set modal width with the width prop.

vue
<AModal v-model="show" title="Wide Modal" width="800px">
  This modal is 800px wide.
</AModal>

Hide the footer button area.

vue
<AModal v-model="show" title="No Footer">
  This modal has no footer buttons.
</AModal>

Confirm Loading

Shows loading state on the confirm button to prevent duplicate submissions.

vue
<script setup>
const show = ref(false)
const loading = ref(false)

function onConfirm() {
  loading.value = true
  setTimeout(() => {
    loading.value = false
    show.value = false
  }, 2000)
}
</script>

<AModal v-model="show" title="Confirm Action" :confirm-loading="loading" @confirm="onConfirm">
  Are you sure?
</AModal>

Use the footer slot to customize the bottom buttons.

vue
<AModal v-model="show" title="Long Content Example">
  <p>The modal content area can hold any content.</p>
  <template #footer>
    <ABtn variant="ghost" @click="show = false">Later</ABtn>
    <ABtn variant="primary" @click="show = false">Got it</ABtn>
  </template>
</AModal>

API

Props

NameTypeDefaultDescription
modelValuebooleanfalseVisibility
titlestringTitle
widthstring'520px'Modal width
closablebooleantrueShow close button, support Esc
maskClosablebooleantrueClose on mask click
confirmTextstring'确认'Confirm button text
cancelTextstring'取消'Cancel button text
confirmLoadingbooleanfalseConfirm button loading

Events

NameDescription
update:modelValueVisibility changed
openModal opened
closeModal closed
confirmConfirm button clicked
cancelCancel button clicked

Slots

NameDescription
defaultModal body content
headerCustom header (overrides title)
footerCustom footer (overrides default buttons)

Interaction

  • Opens with panel animating from scale(0.92) translateY(12px) to normal state with spring curve
  • Closes with panel scaling to scale(0.96) and mask fading out
  • Mask click closes (disable via maskClosable)
  • Esc key closes (disable via closable)
  • Body scroll locked on open, restored on close

MIT License