gpt4 book ai didi

node.js - webview:需求未定义

转载 作者:行者123 更新时间:2023-12-03 12:35:46 26 4
gpt4 key购买 nike

在我的 Electron 应用程序中,我正在设置网络 View 。这是来自index.html的摘录:

  <webview
class="hide"
preload="./preload.js"
nodeintegration
></webview>

<script>
require('./renderer.js');
</script>

在main.js中,我为BrowserWindow设置了 nodeIntegration:false,但是该应用程序无法启动,因为在Webview的控制台中出现此错误:
Uncaught ReferenceError: require is not defined

如果我从main.js中删除 nodeIntegration:false,它可以工作,但是我不想公开 Node API。

(注:Webview指向的远程Web应用程序正在使用jQuery。可能会发生冲突?)

最佳答案

如果删除nodeIntegration : false命令,则不会设置require这样的命令。

看来您有2种可能性:

  • nodeIntegration: false并对其进行处理
  • 就像在浏览器中一样调用您的js文件:<script src="pathToFile"></script>

  • https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron在这里,他们解释 nodeIntegration的真正作用

    关于node.js - webview:需求未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47595830/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com