electron踩坑之remote of undefined的解决

2022-01-13,,,

这篇文章主要介绍了electron踩坑之remote of undefined解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

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

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

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

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

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

问题解决,踩坑完毕。

到此这篇关于electron踩坑之remote of undefined的解决的文章就介绍到这了,更多相关electron remote of undefined内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!

以上就是electron踩坑之remote of undefined的解决的详细内容,更多请关注本站其它相关文章!

《electron踩坑之remote of undefined的解决.doc》

下载本文的Word格式文档,以方便收藏与打印。