栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

electron踩坑之remote of undefined的解决

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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,
    
    webPreferences:{
      nodeIntegration:true,
      enableRemoteModule:true
    }
  })

问题解决,踩坑完毕。

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/68363.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号