useIpcRenderer
useIpcRenderer
ipcRenderer とそのすべてのAPIを提供します。
使用法
import { useIpcRenderer } from '@vueuse/electron'
import { computed } from 'vue'
// ipcRendererを明示的に提供しない場合はnodeIntegrationを有効にしてください
// 参照: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
const ipcRenderer = useIpcRenderer()
// Refの結果が返されます
const result = ipcRenderer.invoke<string>('custom-channel', 'some data')
const msg = computed(() => result.value?.msg)
// unmounted時にリスナーを自動的に削除
ipcRenderer.on('custom-event', (event, ...args) => {
console.log(args)
})
© 2019–PRESENT Anthony Fu https://github.com/antfu
※このページは Nuxt.js 公式ドキュメントの翻訳ページです。
公式ドキュメントの該当ページはこちら:
#