如何解决为什么电子中的IpcRender构建到.exe文件后没有从BrowserWindow.send获得任何值
我有一个问题,我不知道问题的确切原因是什么,我在index.js
中有简单的代码作为主代码,在index.html
中有简单的代码,脚本将发送该版本电子到渲染器文件main.js
中,当我在将该脚本构建到index.html
中之前尝试使用该命令时,.exe
可以从发送的值中获取值,以下是我在构建之前运行的图像像这样的ipcRenderer
文件:
image that run before build into .exe
但是当我使用.exe
electron-packager .
发送html文件中的版本后,它没有返回任何值,下面的图像是这样的,而当我像这样构建到index.js
文件后运行时,下面的图像
image that run after build into .exe
这是我的以下脚本和package.json:
.exe
index.js
const { app,BrowserWindow,ipcMain } = require('electron')
function createWindow () {
// Create the browser window.
const win = new BrowserWindow({
width: 800,height: 600,webPreferences: {
nodeIntegration: true,enableRemoteModule : false
}
})
const appVersion = process.env.npm_package_version
// and load the index.html of the app.
win.toggleDevTools()
win.loadFile('index.html')
win.webContents.on('dom-ready',() => {
console.log(`Trying to send app version to renderer: ${appVersion}`)
win.send('app-version',appVersion)
console.log(`Current directory: ${process.cwd()}`);
})
}
app.whenReady().then(createWindow)
index.html
<html>
<head>
<title></title>
</head>
<body>
<div id ="appVersion">
</div>
</body>
</html>
<script>
'use strict'
const { ipcRenderer} = require('electron')
ipcRenderer.on('app-version',function (event,store) {
console.log(store);
});
</script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。