Confirm
Custom confirmation dialogs with async loading, callbacks, promises and Chalk/OEM themes.
The default export is a component plugin; the named Confirm export is the callable service. CommonUI or app.use(NfConfirm) installs this.$openConfirm. In setup, useConfirm() inherits provider injections and locale and cleans up on unmount. createConfirm(appContext) creates an app-scoped service. Direct Confirm does not implicitly bind the last installed app; pass appContext as its second argument when needed.
Basic usage
Status types
Promises and asynchronous close
Callbacks and retry
Text, HTML, VNode and component
Interactive example
Without retry, confirm resolves the Promise and waits for done(). Press Escape to cancel.
Installation
import NfConfirm, { Confirm, useConfirm, createConfirm } from '@94ai-plus/nf-confirm'
import 'element-plus/dist/index.css'
import '@94ai-plus/nf-theme-chalk/nf-confirm.css'
app.use(NfConfirm)
Confirm({ title: 'Confirm', message: 'Continue?' }).then(done => done()).catch(() => {})
// setup(): const confirm = useConfirm()
const confirm = createConfirm(app._context)Options
| Attribute | Description | Type | Accepted values | Default |
|---|---|---|---|---|
| title | Title | string | — | '' |
| message | Description text | string / VNode | — | '' |
| dangerouslyUseHTMLString | Whether to render message as HTML; trusted content only | boolean | — | false |
| width | Confirm width in px | number | — | 400 |
| type | Theme style; unsupported values are ignored | string | success / warning / info / error | '' |
| iconClass | Custom icon class; a valid type takes precedence | string | — | '' |
| customClass | Custom class name | string | — | '' |
| cancelButtonText | Cancel button text | string | — | Current locale |
| confirmButtonText | Confirm button text | string | — | Current locale |
| onCancel | Cancel callback; done() closes Confirm, done(false) only stops loading | (done: ConfirmDone) => void | Promise<void> | — | — |
| onConfirm | Confirm callback; done() closes Confirm, done(false) only stops loading | (done: ConfirmDone) => void | Promise<void> | — | — |
| modelValue | Visibility with v-model; takes precedence over visible | boolean | — | false |
| visible | Visibility with v-model:visible | boolean | — | false |
Events
| Event | Description | Payload |
|---|---|---|
| cancel | Cancel callback; done() closes Confirm, done(false) only stops loading | done: ConfirmDone |
| confirm | Confirm callback; done() closes Confirm, done(false) only stops loading | done: ConfirmDone |
| update:modelValue | Emitted when visibility changes | value: boolean |
| update:visible | Emitted when visibility changes | value: boolean |
| close | Emitted on close | — |
| destroy | Emitted after the leave transition | — |
Slots
| Slot | Description | Payload |
|---|---|---|
| default | Body content; takes precedence over message | — |
Methods and instance
| API | Description |
|---|---|
| Confirm(options?, appContext?) | Promise<ConfirmDone> |
| done() / done(true) | Clear loading and close |
| done(false) | Clear loading, keep dialog open |
| Confirm.closeAll() | Cancel all Confirm instances on the page |
| createConfirm(appContext) / useConfirm() | Scoped service; closeAll only cancels owned instances |
| component ref.close(close?) | Close or clear loading |
Migration notes
Preserves 400px width, 35vh top, four types, both buttons and async loading. No close icon; backdrop clicks do not close. Escape is treated as cancellation, invokes onCancel and rejects with undefined after closing, fixing the legacy unresolved Promise. Default labels follow eight languages; explicit labels win. Recognized type icons take priority over iconClass. Titles/strings are escaped; HTML mode is only for trusted content. VNode content now renders correctly.
Without a custom onConfirm, confirmation resolves with done and does not close automatically. Call done() to close. done(false) only clears loading; a resolved Promise does not run then again. Use onConfirm for retryable operations. With custom callbacks, done(false) keeps the Promise pending; done() settles according to the current action. This fixes promises that never settled with legacy callbacks. Synchronous errors/async rejections clear loading and reject(error), without auto-closing. An internal rejection observer prevents ignored callback-style returns from becoming unhandled; explicit catch still receives cancellations/errors.
Each dialog owns its Promise, fixing the global currentMsg cross-instance bug. Attempt-scoped done functions cannot affect later retries, cancellation or reopened dialogs. Loading blocks repeated confirmation. Adds declarative v-model/v-model:visible, default slot and typed close(); declarative components without action listeners close normally. The default slot is new; the legacy component had no usable slot.
Element Plus Dialog provides focus, scroll locking and layering. App/provider services only clean up owned dialogs; direct Confirm.closeAll() cancels all Confirm instances without touching Message/Notification. Closing/unmount releases the Vue tree; SSR returns a resolved no-op done Promise without DOM access. Dialogs mount into body and follow root data-nf-theme. The duplicate legacy /3 anchor maps to basic usage; its incorrectly named notification Options anchor does not override notification routes.
