files required for front-end communication with business layer ipc
location:
./frontend/src/utils/ipcRenderer.js
API
$ipcInvoke(route, params)
- introduction: send asynchronous messages (invoke/handle model)
- response:Promise
```
Callback syntax
handleInvoke () { this.$ipcInvoke(ipcApiRoute.ipcInvokeMsg, ‘asynchronous-callback’).then(r => {
}); },console.log('r:', r);
async/await
async handleInvoke2 () { const msg = await this.$ipcInvoke(ipcApiRoute.ipcInvokeMsg, ‘asynchronous’); },
<a name="J48mD"></a>
### $ipcSendSync(route, params)
- introduction: send synchronous messages (send/on model)
- response: any type
grammar
const msg = this.$ipcSendSync(ipcApiRoute.ipcSendSyncMsg, ‘synchronization’);
<a name="JhaxB"></a>
### $ipc
- introduction: The global ipc object is equivalent to the ipcRender provided by electron.
This object contains the following methods: on once removeListener removeAllListeners send invoke sendSync postMessage sendTo sendToHost IpcRendererEvent
For more information, see: [https://www.electronjs.org/zh/docs/latest/api/ipc-renderer#ipcrendereronchannel-listener](https://www.electronjs.org/zh/docs/latest/api/ipc-renderer#ipcrendereronchannel-listener)
<a name="KCJ3t"></a>
### $ipc.send(route, params)
- introduction: The send attribute of ipc, send asynchronous messages to the main process. You can send any parameters.
- response: The result is in the route of the $ipc.on() listener.
const params = { type: ‘start’, content: ‘start’ } this.$ipc.send(ipcApiRoute.ipcSendMsg, params)
<a name="laWrY"></a>
### $ipc.on(route, listener)
- introduction: The on attribute of ipc, listener route ; When a new message arrives, the listener is called.
- response:callback
this.$ipc.on(ipcApiRoute.ipcSendMsg, (event, result) => { console.log(‘result:’, result);
// Call another interface of the back end event.sender.send(ipcApiRoute.hello, ‘electron-egg’); }) ```