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
收取;