ipcMain / ipcRenderer (进程间的通讯)

最后更新于:2022-04-02 03:34:34

[TOC] ## ipcMain 与 ipcRenderer 进程间的通讯 [https://electronjs.org/docs/api/ipc-renderer](https://electronjs.org/docs/api/ipc-renderer) ``` ipcRenderer.on(channel, listener) ipcRenderer.once(channel, listener) 只地监听一次后删除 ipcRenderer.removeAllListeners(channel) ipcRenderer.send(channel[, arg1][, arg2][, ...]) ``` main.js ``` //ipcMain 处理 ipcMain.on("main_liston",(event,arg)=>{ console.log(arg); event.sender.send("renderer_liston",'main to renderer') }) ``` other.js ``` const {ipcRenderer} = require('electron'); ipcRenderer.send('main_liston',`renderer to main num:`); ipcRenderer.on('renderer_liston',(event,arg)=>{ //arg }) ```
';