MessageBox
# MessageBox
A set of modal dialog components that simulate system message prompts, used for displaying alerts, confirmation messages, and submission content.
:::tip
From a usage scenario perspective, MessageBox serves to enhance the native system alert, confirm, and prompt functions, thus suitable for displaying relatively simple content. For more complex content, please use Dialog.
:::
# Alert Message
Mobile devices only support $confirm and $message consistently with PC. For other methods, refer to the mobile usage at the bottom.
Triggers when users perform operations, interrupting their workflow until they acknowledge the message.
# Confirmation
Mobile devices only support $confirm and $message consistently with PC. For other methods, refer to the mobile usage at the bottom.
Used to prompt users to confirm triggered actions.
# Prompt
Mobile devices only support $confirm and $message consistently with PC. For other methods, refer to the mobile usage at the bottom.
Interrupts user operations to prompt for input.
# Customization
Mobile devices only support $confirm and $message consistently with PC. For other methods, refer to the mobile usage at the bottom.
Supports fully customized configurations.
:::tip
Content can be VNode, allowing custom components. To force re-rendering when content changes, add unique keys to VNodes.
:::
# HTML Fragments
Not supported on mobile
The message property supports HTML fragments.
:::warning
Dynamic HTML rendering is dangerous (XSS risk). Only enable dangerouslyUseHTMLString when content is trusted. Never assign user-submitted content to message.
:::
# Distinguish Cancel & Close
Differentiate between cancel button clicks and close actions.
# Centered Layout
Supports center-aligned content.
# Global Methods
Mobile devices only support $confirm and $message consistently with PC. For other methods, refer to the mobile usage at the bottom.
When FxUI is fully imported, these global methods are added to Vue.prototype:
$msgbox(options)$alert(message, title, options)or$alert(message, options)$confirm(message, title, options)or$confirm(message, options)$prompt(message, title, options)or$prompt(message, options)
# Import Separately
Not supported on mobile
For individual imports:
import { MessageBox } from 'fx-ui';
Equivalent methods are: MessageBox, MessageBox.alert, MessageBox.confirm, and MessageBox.prompt.
# Options
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| title | MessageBox title | string | — | — |
| message | MessageBox content | string/VNode | — | — |
| dangerouslyUseHTMLString | Treat message as HTML | boolean | — | false |
| type | Message type (icon) | string | success/info/warning/error | — |
| iconClass | Custom icon class (overrides type) | string | — | — |
| customClass | Custom CSS class | string | — | — |
| callback | Callback when not using Promise | function(action, instance) | — | — |
| showClose | Show close button | boolean | — | true |
| beforeClose | Pre-close callback | function(action, instance, done) | — | — |
| distinguishCancelAndClose | Distinguish cancel/close | boolean | — | false |
| lockScroll | Lock body scroll | boolean | — | true |
| showCancelButton | Show cancel button | boolean | — | false |
| showConfirmButton | Show confirm button | boolean | — | true |
| cancelButtonText | Cancel button text | string | — | Cancel |
| confirmButtonText | Confirm button text | string | — | Confirm |
| cancelButtonClass | Cancel button CSS class | string | — | — |
| confirmButtonClass | Confirm button CSS class | string | — | — |
| closeOnClickModal | Close when clicking overlay | boolean | — | true |
| closeOnPressEscape | Close on ESC key | boolean | — | true |
| closeOnHashChange | Close on hashchange | boolean | — | true |
| showInput | Show input field | boolean | — | false |
| inputPlaceholder | Input placeholder | string | — | — |
| inputType | Input type | string | — | text |
| inputValue | Initial input value | string | — | — |
| inputPattern | Input validation regex | regexp | — | — |
| inputValidator | Custom validation function | function | — | — |
| inputErrorMessage | Validation error message | string | — | Invalid input |
| center | Center alignment | boolean | — | false |
| roundButton | Use rounded buttons | boolean | — | false |
# Mobile Usage
# Guidelines
Note: JS object-triggered instances are singleton mode.
# Import Separately
Call
closemethod to dismiss dialog.
this.$dialog({
title: 'Alert',
message: 'Content',
});
# Confirm Dialog
this.$confirm('Content')
.then(() => {
// confirm
})
.catch(() => {
// cancel
});
# beforeClose Interceptor
this.$confirm({
title: 'Confirm',
message: 'Content',
beforeClose: (action, close) => {
if (action === 'confirm') {
} else {
}
},
});
# API
| Option | Description | Type | Values | Default |
|---|---|---|---|---|
| title | Title | String | -- | |
| message | Content | String | -- | |
| className | Root node CSS class | String | -- | |
| showConfirmButton | Show confirm button | Boolean | true | |
| showCancelButton | Show cancel button | Boolean | false | |
| confirmButtonText | Confirm button text | String | Confirm | |
| cancelButtonText | Cancel button text | String | Cancel | |
| showModal | Show overlay | Boolean | true | |
| closeOnClickModal | Close when clicking overlay | Boolean | false | |
| beforeClose | Pre-close callback | Function | -- |