问题描述
我有一个问题,我不知道问题的确切原因是什么,我在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 (将#修改为@)