mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
* fix: add missing EventsOffAll export to runtime templates The EventsOffAll function was implemented in the internal runtime (desktop/events.js) and exported in the wrapper runtime files, but was missing from the public runtime templates that are generated in user projects. This caused a type mismatch where EventsOffAll was declared in the TypeScript definition but the implementation was missing. This commit adds the EventsOffAll export and type declaration to all frontend framework templates: - Common templates (generate/assets/common) - React / React-TS - Vue / Vue-TS - Svelte / Svelte-TS - Preact / Preact-TS - Lit / Lit-TS - Vanilla / Vanilla-TS Fixes #4703 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * docs: add EventsOffAll to runtime events documentation Added EventsOffAll function documentation to both English and Chinese versions of the runtime events reference. The function was already implemented in Go (pkg/runtime/events.go) and JavaScript (internal/frontend/runtime/desktop/events.js), but was missing from the public documentation. Related to #4703 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * chore: add EventsOffAll fix to changelog Added entry for the EventsOffAll fix to the Unreleased section of the changelog. Related to #4703 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * docs: translate EventsOffAll description to Chinese Improved consistency in Chinese documentation by translating the EventsOffAll description from English to Chinese, matching the style of other event method descriptions. Related to #4703 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: cc <Zhuanz@MacBook-Pro.local> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
44 lines
2.3 KiB
Text
44 lines
2.3 KiB
Text
---
|
|
sidebar_position: 2
|
|
---
|
|
|
|
# Events 事件
|
|
|
|
Wails 运行时提供了一个统一的事件系统,其中事件可以由 Go 或 JavaScript 发出或接收。 可选地,数据可以与事件一起传递。 侦听器将接收本地数据类型中的数据。
|
|
|
|
### EventsOn 添加事件侦听器
|
|
|
|
此方法为给定的事件名称设置一个侦听器。 当 [触发指定事件](#触发指定事件) 名为 `eventName` 类型的事件时,将触发回调。 与触发事件一起发送的任何其他数据都将传递给回调。 它返回 一个函数来取消侦听器。
|
|
|
|
Go: `EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/> JS: `EventsOn(eventName string, callback function(optionalData?: any)): () => void`
|
|
|
|
### EventsOff 移除事件侦听器
|
|
|
|
This method unregisters the listener for the given event name, optionally multiple listeners can be unregistered via `additionalEventNames`.
|
|
|
|
Go: `EventsOff(ctx context.Context, eventName string, additionalEventNames ...string)`<br/> JS: `EventsOff(eventName string, ...additionalEventNames)`
|
|
|
|
### EventsOffAll 移除所有事件侦听器
|
|
|
|
此方法注销所有事件侦听器。
|
|
|
|
Go: `EventsOffAll(ctx context.Context)`<br/>
|
|
JS: `EventsOffAll()`
|
|
|
|
### EventsOnce 添加只触发一次的事件侦听器
|
|
|
|
此方法为给定的事件名称设置一个侦听器,但只会触发一次。 它返回 一个函数来取消侦听器。
|
|
|
|
Go: `EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/> JS: `EventsOnce(eventName string, callback function(optionalData?: any)): () => void`
|
|
|
|
### EventsOnMultiple 添加指定对多触发次数的事件侦听器
|
|
|
|
此方法为给定的事件名称设置一个侦听器,但最多只能触发 `counter` 次。 它返回 一个函数来取消侦听器。
|
|
|
|
Go: `EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int) func()`<br/> JS: `EventsOnMultiple(eventName string, callback function(optionalData?: any), counter int): () => void`
|
|
|
|
### EventsEmit 触发指定事件
|
|
|
|
此方法触发指定的事件。 可选数据可以与事件一起传递。 这将触发任意事件侦听器。
|
|
|
|
Go: `EventsEmit(ctx context.Context, eventName string, optionalData ...interface{})`<br/> JS: `EventsEmit(eventName: string, ...optionalData: any)`
|