Events     

Events are important for the inner workings of your App.
Sometimes you need an event bus or a publish/subscribe channel. Quasar provides this out of the box:

import { Events } from 'quasar'
Events.$on('app:visibility', state => {
console.log('App became', state)
})

Essentially, Events is just a Vue event bus that you can use throughout your App. If you know how to use Vue events, then you’re all set to go.

Methods

Registering for an Event

Events.$on(String eventName, Function callback)

Example:

import { Events } from 'quasar'
Events.$on('some-event', (param1, param2) => {
//...
})

Removing Callback for an Event

Events.$off(String eventName [, Function callback])

import { Events } from 'quasar'
// Unregistering an event:
Events.$off('event-name')
// 'event-name' does no longer has any callbacks
// Unregistering a specific callback for an event:
let callback = function(...) {...}
Events.$on('event-name', callback)
Events.$off('event-name', callback)
// 'event-name' still exists (if other callbacks are registered to this event),
// but does not contain the above callback anymore

Registering a Callback to Be Run Only Once

Events.$once(String eventName, Function callback)

Sometimes you need to trigger a callback only once. Example:

import { Events } from 'quasar'
let callback = function(...) {...}
Events.$once('event-name', callback)
// callback will be triggered only once

Triggering an Event

Events.$emit(String eventName [, Anything *arg])

Example:

import { Events } from 'quasar'
Events.$emit('event-name')
// All callbacks associated with 'event-name' will be triggered
// in the order that they were registered.
// Trigger with parameters (as many as you want):
Events.$emit('event-name', {
status: 10,
message: 'wow',
{obj: true}
)
// The parameters will be used when calling all registered
// callbacks for 'event-name' --> callback({status: 10, message: 'wow',...});

Quasar Events List

There are some events emitted by Quasar already that you can hook into.

Global Events

Event NameDescription
app:errorTriggered for any Javascript error. See parameters below.

Parameter supplied by app:error

app:error event is triggerd with one parameter, an Object containing the following properties:

Property NameTypeDescription
messageStringError message
sourceStringURL of the script where the error was raised
linenoNumberLine number where error was raised
colnoNumberColumn number for the line where the error occurred
errorObjectError Object containing amongst other things the stack trace

App Visibility

Event NameParametersDescription
app:visibility(String) stateApp got focus if state is visible or lost focus if state is hidden

Read more about it here.

Toast

Event NameParametersDescription
app:notify(String) htmlIs triggered whenever a Toast is displayed.

Read more about it here.

Loading

Event NameParametersDescription
app:loading(Boolean) statusTriggered when Loading component is displayed (with true as param) or hidden (with false as param).

Read more about it here.