Skip to content

useIpcRenderer

提供 ipcRenderer 及其所有 API。

¥Provides ipcRenderer and all of its APIs. Available in the @vueuse/electron add-on.

用法

¥Usage

ts
import { 
useIpcRenderer
} from '@vueuse/electron'
import {
computed
} from 'vue'
// enable nodeIntegration if you don't provide ipcRenderer explicitly // see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration const
ipcRenderer
=
useIpcRenderer
()
// Ref result will return const
result
=
ipcRenderer
.
invoke
<string>('custom-channel', 'some data')
const
msg
=
computed
(() =>
result
.
value
?.msg)
// remove listener automatically on unmounted
ipcRenderer
.
on
('custom-event', (
event
, ...
args
) => {
console
.
log
(
args
)
})
js
import { useIpcRenderer } from '@vueuse/electron'
import { computed } from 'vue'
// enable nodeIntegration if you don't provide ipcRenderer explicitly
// see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
const ipcRenderer = useIpcRenderer()
// Ref result will return
const result = ipcRenderer.invoke('custom-channel', 'some data')
const msg = computed(() => result.value?.msg)
// remove listener automatically on unmounted
ipcRenderer.on('custom-event', (event, ...args) => {
  console.log(args)
})