useIpcRendererOn
轻松使用 ipcRenderer.on,并在组件卸载时自动移除监听器 ipcRenderer.removeListener。 Available in the @vueuse/electron add-on.
用法
ts
import { useIpcRendererOn } from '@vueuse/electron'
// 如果没有显式提供 ipcRenderer,请启用 nodeIntegration
// 参见:https://www.electronjs.org/docs/api/webview-tag#nodeintegration
// 在组件卸载时自动移除监听器
useIpcRendererOn('custom-event', (event, ...args) => {
console.log(args)
})
类型声明
显示类型声明
typescript
/**
* Listens to channel, when a new message arrives listener would be called with listener(event, args...).
* [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
*
* You need to provide `ipcRenderer` to this function.
*
* @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
* @see https://vueuse.org/useIpcRendererOn
*/
export declare function useIpcRendererOn(
ipcRenderer: IpcRenderer,
channel: string,
listener: IpcRendererListener,
): IpcRenderer
/**
* Listens to channel, when a new message arrives listener would be called with listener(event, args...).
* [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
*
* `ipcRenderer` will be automatically gotten.
*
* @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
* @see https://vueuse.org/useIpcRendererOn
*/
export declare function useIpcRendererOn(
channel: string,
listener: IpcRendererListener,
): IpcRenderer
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
ArcherGu
变更日志
v10.0.0-beta.5
on 4/13/2023cb644
- refactor!: remove isFunction
and isString
utils