useNotify
Toast notifications on top of Notivue push. error() also understands API errors, so you can pass a caught error directly.
Registered only when we.notify.enabled is true (default). Toasts are rendered by WeNotification, which must be mounted once in your app (e.g. in app.vue).
Usage
const notify = useNotify()
notify.success('Saved')
notify.info({ title: 'Heads up', message: 'Export started' })
try {
await useApi().$post('orders', order, { notify: false })
} catch (e) {
notify.error(e) // shows the API `message` when present
}Return Value
| Method | Description |
|---|---|
success | push.success |
error | Wrapper of push.error (see below) |
info | push.info |
warning / warn | push.warning |
promise | push.promise — a loading toast you later resolve/reject |
load | push.load |
clearAll | push.clearAll — dismiss all toasts (with leave animation) |
destroyAll | push.destroyAll — remove all toasts immediately |
All methods except error are the Notivue functions themselves: they accept a string or a Notivue options object and return the notification handle. See the Notivue push docs for options.
error(opts)
opts can be a string, a Notivue options object, an Error, or an ofetch error / context. The message shown is, in order:
opts.response._data.message(the Laravel error message), if present;opts.message, ifoptsis anError;optsas given.
error returns nothing.
useApi already calls error() on failed responses (except 401, 404 and 422) unless the request has notify: false.
Example: promise toast
const notify = useNotify()
const toast = notify.promise('Importing…')
try {
await useApi().$post('imports', payload)
toast.resolve('Import completed')
} catch (e) {
toast.reject('Import failed')
}Options API
With we.notify.optionsApi (default true) a separate this.$notify helper is available, with a different signature (info/success/warn/error(title, text?, options?)). See Options API.