ipcMain
const { ipcMain } = require("electron");
ipcMain.handle("click-me", (_, msg) => {
return "<----" + msg + "---->";
})
ipcRenderer
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("electron", {
platform: process.platform,
clickMe: (msg) => ipcRenderer.invoke("click-me", msg)
});
App.vue
<script lang="ts" setup>
import {ref} from "vue";
const result = ref("")
const message = ref("")
async function handleClick() {
result.value = await window.electron.clickMe(message.value)
}
</script>
<template>
<input v-model="message"/>
<button @click="handleClick">click me</button>
<p>{{ result }}</p>
</template>
簡單梳理
- 頁面點選;
ipcRenderer
傳送;
ipcMain
處理和返回;
ipcRenderer
收取;