files required for front-end communication with business layer ipc

location:

  1. ./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 => {
    1. console.log('r:', r);
    }); },

async/await

async handleInvoke2 () { const msg = await this.$ipcInvoke(ipcApiRoute.ipcInvokeMsg, ‘asynchronous’); },

  1. <a name="J48mD"></a>
  2. ### $ipcSendSync(route, params)
  3. - introduction: send synchronous messages (send/on model)
  4. - response: any type

grammar

const msg = this.$ipcSendSync(ipcApiRoute.ipcSendSyncMsg, ‘synchronization’);

  1. <a name="JhaxB"></a>
  2. ### $ipc
  3. - 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

  1. 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)
  2. <a name="KCJ3t"></a>
  3. ### $ipc.send(route, params)
  4. - introduction: The send attribute of ipc, send asynchronous messages to the main process. You can send any parameters.
  5. - response: The result is in the route of the $ipc.on() listener.

const params = { type: ‘start’, content: ‘start’ } this.$ipc.send(ipcApiRoute.ipcSendMsg, params)

  1. <a name="laWrY"></a>
  2. ### $ipc.on(route, listener)
  3. - introduction: The on attribute of ipc, listener route ; When a new message arrives, the listener is called.
  4. - 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’); }) ```