pub fn emit<E, P>(event: E, payload: &P) -> Result<Emit<E::Js>, Error>
Available on crate feature
serde
only.Expand description
Sends an event to the backend.
§Example
Send an event with string payload.
tauri_wasm::emit("file-selected", "/path/to/file")?.await?;
You can send any serializable payload.
use serde::Serialize;
#[derive(Serialize)]
struct Message {
key: &'static str,
data: u32,
}
let message = Message {
key: "secret",
data: 37,
};
tauri_wasm::emit("file-selected", &message)?.await?;
To trigger an event to a listener registered by a specific target
you can use the to
function.
§Capabilities
Note that in order to emit events, the Tauri framework
requires the corresponding capabilities to be enabled.
For example, let’s say our application and its window
are named “app”. Then your Tauri.toml
config should
include something like:
[app]
# app configs..
[[app.security.capabilities]]
identifier = "default"
windows = ["app"]
permissions = ["core:event:default"]