Tauri listen
listen<>(: EventName, : EventCallback<>): Promise< UnlistenFnTeventhandlerT>
从后端侦听事件。
例
import { listen } from '@tauri-apps/api/event';
const unlisten = await listen<string>('error', (event) => {
console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();Since: 1.0.0
类型参数
-
T
参数
| 名字 | 类型 | 描述 |
|---|---|---|
event | EventName | 事件名称。必须仅包含字母数字字符 、 和 。-/:_ |
handler | EventCallback<T> | 事件处理程序回调。 |
Returns: Promise<UnlistenFn>
解析为函数以取消侦听事件的承诺。 请注意,如果侦听器超出范围,则需要删除侦听器,例如卸载组件。