【发布时间】:2020-08-19 15:24:12
【问题描述】:
这看起来应该很简单。我在 main.js 中有一行写着:
event.sender.send("name-prompt")
我知道这个正在被调用,当我尝试传入event 时收到警告。然后在index.js我有
ipcRenderer.on("name-prompt", () => {
console.log("why isn't this working")
document.getElementById("details-prompt").classList.add("visibility-override")
})
而且这永远不会运行。 webContents.send and ipcRenderer.on Not Working 使用 webContents.send,据我了解,它与 event.sender.send 不同。我对电子肯定很陌生,所以我错过了很多东西。我应该怎么做才能完成这项工作?
编辑:IPCMain.on 的完整代码
ipcMain.on("add-from-file-clicked", (event) => {
dialog.showOpenDialog({ properties: ['openFile'] }).then(result => {
console.log(result.canceled);
console.log(result.filePaths);
if (!result.canceled) {
event.sender.send("name-prompt")
}
})
})
是的,我已经验证了 result.canceled 是假的。谢谢!
【问题讨论】:
-
在 main.js 中创建
BrowserWindow时启用nodeIntegration -
@tpikachu 我启用了 nodeIntegration,据我所知,如果我不这样做,它甚至都不会工作。
-
让我看看你正在从渲染器收听的 ipcMain 部分
-
@tpikachu 当然,谢谢
标签: javascript node.js electron