gpt4 book ai didi

javascript - Electron.js如何在HTML脚本标记中使用require函数

转载 作者:行者123 更新时间:2023-12-03 12:42:05 24 4
gpt4 key购买 nike

你好。

我正在尝试使用Electron.js开发应用程序。我有个问题。我需要html中的脚本标签。但是当我这样做时,我的其他JavaScript代码不起作用。我该怎么办?

跑:

!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Application</title>
</head>
<body>

<button id="tstbtn">TEST BUTTON</button>

<script>
//const ElectronLIB = require("electron");

let tstbtn = document.querySelector("#tstbtn");
tstbtn.addEventListener("click", () => {
alert();
})

</script>

</body>
</html>

不要运行:
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Application</title>
</head>
<body>

<button id="tstbtn">TEST BUTTON</button>

<script>
const ElectronLIB = require("electron");

let tstbtn = document.querySelector("#tstbtn");
tstbtn.addEventListener("click", () => {
alert();
})

</script>

</body>
</html>

注意:稍后我调用require函数时,click事件正在运行。

最佳答案

DevTool中是否有任何错误信息?喜欢:

Uncaught ReferenceError: require is not defined.



如果有错误,可以在打开时启用nodeIntegration
BrowserWindow, for example 
splashWindow = new BrowserWindow({
width: 900,
height: 600,
show: true,
frame: false,
resizable: false,
webPreferences: {
nodeIntegration: true
}
});

关于javascript - Electron.js如何在HTML脚本标记中使用require函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59803490/

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