問題描述
我目前無法在 main.js 文件之外的 Javascript 文件中加載 Electron 模塊.
I'm currently unable to load Electron modules in Javascript files outside of the main.js file.
我正在嘗試使用:
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
在名為 settings.js 的文件中.
in a file called settings.js.
我安裝了正確的 NPM 模塊(eletron-prebuilt).
I have the correct NPM modules installed (eletron-prebuilt).
設置頁面在 webview 中加載,如下所示:
The settings page is loaded in a webview like so:
<webview id="settings" src="./settings.html"></webview>
其中包括的 settings.js 如下:
and the settings.js included like:
<script type='text/javascript' src='./resources/js/settings.js'></script>
這里的想法用完了,但我想知道這是否是某種范圍界定問題?
Running out of ideas here, but I wonder if it's some kind of scoping issue?
非常感謝.
推薦答案
你在一個不支持 nodeintegration 默認.
You're loading it in a webview, which doesn't support nodeintegration by default.
將 nodeintegration
屬性添加到您的 webivew.
Add the nodeintegration
attribute to your webivew.
<webview id="settings" src="./settings.html" nodeintegration></webview>
這篇關于在 Electron HTML 頁面中未定義 require()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!