Theme Documentation
Confirm Modal
The confirm modal component is used to display information, warnings, errors, or success messages that require user confirmation. It supports various types and callback functions.
Features
- Multiple types (confirm, info, warning, error, success)
- Different icons and colors for each type
- Supports asynchronous callback functions
- Global singleton implementation
- Based on Pinia state management
- Dark mode support
Component Examples
Basic Usage
The confirm modal has multiple types, each with different icons and color schemes.
300px
Callback Function
The confirm modal supports asynchronous callback functions executed when the user clicks the confirm button.
300px
API Usage
Methods obtained through useConfirm() can display different types of modals:
useConfirm()
import { useConfirm } from '~/composables/useConfirm' const { confirm, info, success, warning, error } = useConfirm()
confirm(title, desc, callback)
Open confirm modal
confirm('确认标题', '您确定要执行此操作吗?', async () => { // 异步操作,按钮会显示加载状态 await someAsyncOperation() })
info(title, desc, callback?)
Open info modal
info('信息标题', '这是一条重要信息。')
success(title, desc, callback?)
Open success modal
success('成功标题', '操作已成功完成!')
warning(title, desc, callback?)
Open warning modal
warning('警告标题', '此操作存在风险。')
error(title, desc, callback?)
Open error modal
error('错误标题', '操作失败,请重试。')
Component Properties
Property | Description | Type | Default |
---|---|---|---|
title | Modal title | string | '' |
desc | Modal description text | string | '' |
callback | Callback function executed when the confirm button is clicked | Function | null |
type | Modal type (confirm, info, success, warning, error) | 'confirm' | 'info' | 'success' | 'warning' | 'error' | 'confirm' |
Design Empowers, Innovation Unlimited