Skip to content

useNotification

统一的通知提示。

参数

名称类型默认值描述
optionsNotificationOptions{}通知属性。参考 ElementPlus Notification Props

返回值

名称类型描述
primaryprimary(message: string, title?: string)显示主要通知
successsuccess(message: string, title?: string)显示成功通知
errorerror(message: string, title?: string)显示错误通知
warningwarning(message: string, title?: string)显示警告通知
infoinfo(message: string, title?: string)显示信息通知
closeAllcloseAll()关闭所有通知

基础用法

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()

带标题

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

const { success } = useNotification()

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

自定义用法

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()

基于 MIT 许可证发布。