为什么电子中的IpcRender构建到.exe文件后没有从BrowserWindow.send获得任何值

问题描述

我有一个问题,我不知道问题的确切原因是什么,我在index.js中有简单的代码作为主代码,在index.html中有简单的代码,脚本将发送该版本电子到渲染器文件main.js中,当我在将该脚本构建到index.html中之前尝试使用该命令时,.exe可以从发送的值中获取值,以下是我在构建之前运行的图像像这样的ipcRenderer文件:

image that run before build into .exe

但是当我使用.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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...