event
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
The event system allows you to emit events to the backend and listen to events from it.
This package is also accessible with window.__TAURI__.event when app.withGlobalTauri in tauri.conf.json is set to true.
Enumerations
Section titled “Enumerations”TauriEvent
Section titled “TauriEvent”1.1.0
Enumeration Members
Section titled “Enumeration Members”DRAG_DROP
Section titled “DRAG_DROP”DRAG_DROP: "tauri://drag-drop";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L73
DRAG_ENTER
Section titled “DRAG_ENTER”DRAG_ENTER: "tauri://drag-enter";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L71
DRAG_LEAVE
Section titled “DRAG_LEAVE”DRAG_LEAVE: "tauri://drag-leave";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L74
DRAG_OVER
Section titled “DRAG_OVER”DRAG_OVER: "tauri://drag-over";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L72
WEBVIEW_CREATED
Section titled “WEBVIEW_CREATED”WEBVIEW_CREATED: "tauri://webview-created";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L70
WINDOW_BLUR
Section titled “WINDOW_BLUR”WINDOW_BLUR: "tauri://blur";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L64
WINDOW_CLOSE_REQUESTED
Section titled “WINDOW_CLOSE_REQUESTED”WINDOW_CLOSE_REQUESTED: "tauri://close-requested";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L61
WINDOW_CREATED
Section titled “WINDOW_CREATED”WINDOW_CREATED: "tauri://window-created";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L67
WINDOW_DESTROYED
Section titled “WINDOW_DESTROYED”WINDOW_DESTROYED: "tauri://destroyed";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L62
WINDOW_FOCUS
Section titled “WINDOW_FOCUS”WINDOW_FOCUS: "tauri://focus";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L63
WINDOW_MOVED
Section titled “WINDOW_MOVED”WINDOW_MOVED: "tauri://move";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L60
WINDOW_RESIZED
Section titled “WINDOW_RESIZED”WINDOW_RESIZED: "tauri://resize";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L59
WINDOW_RESUMED
Section titled “WINDOW_RESUMED”WINDOW_RESUMED: "tauri://resumed";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L69
WINDOW_SCALE_FACTOR_CHANGED
Section titled “WINDOW_SCALE_FACTOR_CHANGED”WINDOW_SCALE_FACTOR_CHANGED: "tauri://scale-change";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L65
WINDOW_SUSPENDED
Section titled “WINDOW_SUSPENDED”WINDOW_SUSPENDED: "tauri://suspended";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L68
WINDOW_THEME_CHANGED
Section titled “WINDOW_THEME_CHANGED”WINDOW_THEME_CHANGED: "tauri://theme-changed";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L66
Interfaces
Section titled “Interfaces”Event<T>
Section titled “Event<T>”Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
event |
EventName |
Event name | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L32 |
id |
number |
Event identifier used to unlisten | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L34 |
payload |
T |
Event payload | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L36 |
Options
Section titled “Options”Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
target? |
string | EventTarget |
The event target to listen to, defaults to { kind: 'Any' }, see EventTarget. If a string is provided, EventTarget.AnyLabel is used. |
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L52 |
Type Aliases
Section titled “Type Aliases”EventCallback()<T>
Section titled “EventCallback()<T>”type EventCallback<T>: (event) => void;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
Event<T> |
Returns
Section titled “Returns”void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L39
EventName
Section titled “EventName”type EventName: `${TauriEvent}` | string & Record<never, never>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L44
EventTarget
Section titled “EventTarget”type EventTarget: | object | object | object | object | object | object;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L22
UnlistenFn()
Section titled “UnlistenFn()”type UnlistenFn: () => void;Returns
Section titled “Returns”void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L42
Functions
Section titled “Functions”emit()
Section titled “emit()”function emit<T>(event, payload?): Promise<void>Emits an event to all targets.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
string |
Event name. Must include only alphanumeric characters, -, /, : and _. |
payload? |
T |
Event payload. |
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”import { emit } from '@tauri-apps/api/event';await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L188
emitTo()
Section titled “emitTo()”function emitTo<T>( target, event,payload?): Promise<void>Emits an event to all targets matching the given target.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
target |
string | EventTarget |
Label of the target Window/Webview/WebviewWindow or raw EventTarget object. |
event |
string |
Event name. Must include only alphanumeric characters, -, /, : and _. |
payload? |
T |
Event payload. |
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”import { emitTo } from '@tauri-apps/api/event';await emitTo('main', 'frontend-loaded', { loggedIn: true, token: 'authToken' });2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L210
listen()
Section titled “listen()”function listen<T>( event, handler,options?): Promise<UnlistenFn>Listen to an emitted event to any target.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
EventName |
Event name. Must include only alphanumeric characters, -, /, : and _. |
handler |
EventCallback<T> |
Event handler callback. |
options? |
Options |
Event listening options. |
Returns
Section titled “Returns”A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Section titled “Example”import { listen } from '@tauri-apps/api/event';const unlisten = await listen<string>('error', (event) => { console.log(`Got error, payload: ${event.payload}`);});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmountedunlisten();1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L115
once()
Section titled “once()”function once<T>( event, handler,options?): Promise<UnlistenFn>Listens once to an emitted event to any target.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
EventName |
Event name. Must include only alphanumeric characters, -, /, : and _. |
handler |
EventCallback<T> |
Event handler callback. |
options? |
Options |
Event listening options. |
Returns
Section titled “Returns”A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Section titled “Example”import { once } from '@tauri-apps/api/event';interface LoadedPayload { loggedIn: boolean, token: string}const unlisten = await once<LoadedPayload>('loaded', (event) => { console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmountedunlisten();1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L159
© 2026 Tauri Contributors. CC-BY / MIT