Skip to content

useIpcRendererInvoke

类别
导出体积
218 B
依赖包
@vueuse/electron
上次更改
4 months ago

响应式的 ipcRenderer.invoke API 结果。使异步操作看起来像同步的。 Available in the @vueuse/electron add-on.

用法

ts
import { useIpcRendererInvoke } from '@vueuse/electron'

// 如果没有明确提供 ipcRenderer,则需要启用 nodeIntegration
// @see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
// Ref 结果将返回
const result = useIpcRendererInvoke<string>('custom-channel', 'some data')
const msg = computed(() => result.value?.msg)
js
import { useIpcRendererInvoke } from '@vueuse/electron'
// 如果没有明确提供 ipcRenderer,则需要启用 nodeIntegration
// @see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
// Ref 结果将返回
const result = useIpcRendererInvoke('custom-channel', 'some data')
const msg = computed(() => result.value?.msg)

类型声明

typescript
/**
 * 返回 Promise<any> - 解析为来自主进程的响应。
 *
 * 通过频道发送消息到主进程,并期待结果 ~~异步~~。作为组合 API,它使得异步操作看起来像同步的。
 *
 * 你需要为此函数提供 `ipcRenderer`。
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererinvokechannel-args
 * @see https://vueuse.org/useIpcRendererInvoke
 */
export declare function useIpcRendererInvoke<T>(
  ipcRenderer: IpcRenderer,
  channel: string,
  ...args: any[]
): Ref<T | null>
/**
 * 返回 Promise<any> - 解析为来自主进程的响应。
 *
 * 通过频道发送消息到主进程,并期待结果 ~~异步~~。作为组合 API,它使得异步操作看起来像同步的。
 *
 * `ipcRenderer` 将自动获取。
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererinvokechannel-args
 * @see https://vueuse.org/useIpcRendererInvoke
 */
export declare function useIpcRendererInvoke<T>(
  channel: string,
  ...args: any[]
): Ref<T | null>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Curt Grimes
ArcherGu

更新日志

v10.0.0-beta.5 on 4/13/2023
cb644 - refactor!: remove isFunction and isString utils