Skip to content

useNotification

Unified notification prompt.

Parameters

NameTypeDefaultDescription
optionsNotificationOptions{}Notification props. Reference ElementPlus Notification Props

Returns

NameTypeDescription
primaryprimary(message: string, title?: string)Show primary notification
successsuccess(message: string, title?: string)Show success notification
errorerror(message: string, title?: string)Show error notification
warningwarning(message: string, title?: string)Show warning notification
infoinfo(message: string, title?: string)Show info notification
closeAllcloseAll()Close all notifications

Basic Usage

ts
import { useNotification } from '@vuecraft/components'

const { primary, success, error, warning, info, closeAll } = useNotification()

primary('Primary message')
success('Success message')
error('Error message')
warning('Warning message')
info('Info message')
closeAll()

With Title

ts
import { useNotification } from '@vuecraft/components'

const { success } = useNotification()

success('Success message', 'Success Title')

Custom Usage

ts
import { useNotification } from '@vuecraft/components'

const { primary, success, error, warning, info, closeAll } = useNotification({
  duration: 5000,
  showClose: false,
  position: 'bottom-right',
  title: 'Default Title',
  onClick: () => {
    console.log('notification clicked')
  },
  onClose: () => {
    console.log('notification closed')
  },
})

success('Success message')
error('Error message', 'Error Title')
closeAll()

Released under the MIT License.