我试图在ipcRenderer和IPCMain之间做一个非常简单的通信,但它不起作用!有人能告诉我为什么吗?
GALLERY.JS
const { ipcRenderer } = require("electron");
document.addEventListener('DOMContentLoaded', (e) => {
ipcRenderer.send('test');
});我真的不明白为什么我的控制台什么都没有打印出来
GALERYCONTROLLER.JS
const { ipcMain} = require('electron');
const userId;
const Axios = require('axios')
ipcMain.on('test', (e) =>{
console.log('droneDataGallery received')
})
});gallery.ejs
<link rel="stylesheet" href="../assets/css/GalleryPage.css"></link>
<div class='galleryPage'>
</div>
<script src="./../assets/js/gallery.js"></script>非常感谢你的帮助!
发布于 2021-10-12 07:42:59
假设您使用的是最新版本的Electron,则需要在preload.js级别通过contextBrige对象将ipc消息传递系统公开给您的超文本标记语言(gallery.js)代码。This is very well explained here,它对我来说很有效。当然,这意味着一些额外的管道。
https://stackoverflow.com/questions/69520382
复制相似问题