之前的项目,引用electron的remote可以直接调用 electron.remote 来去使用,而近期使用electron却频繁报错???踩坑后我快速去查看了下官方文档,是不是electron进行了更新?果然不出所料,在electron 10中,修改了enableRemoteModule默认为false,我们需要手动将其修改为true。

electron踩坑之remote of undefined的解决

此前版本中我们使用electron中的remote模块时,不需在主进程的窗口中加入 enableRemoteModule:true 参数才能够调用remote模块,而在 electron 10 中,我们需要加入该参数才能调用该模块。

//引入electron
let electron = require('electron')
//引入remote模块
let remote = electron.remote
//打印remote模块
console.log(remote)

在未加入参数前,会引起报错。

electron踩坑之remote of undefined的解决

而在主进程中我们需要向 webPreferences 配置参数 enableRemoteModule:true 来打开remote模块,使得渲染进程中可以调用主进程的方法,我们需要对mianWindow来配置:

mainWindow = new BrowserWindow({
    width:600,
    height:800,
    /* 启用Node继承 */
    webPreferences:{
      nodeIntegration:true,
      enableRemoteModule:true
    }
  })

问题解决,踩坑完毕。

标签:
electron,remote,of,undefined,electron,remote

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“electron踩坑之remote of undefined的解决”

暂无“electron踩坑之remote of undefined的解决”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。