我试图在express中使用我的“ window”变量,但我不能。谁能帮忙
const { app, BrowserWindow } = require("electron")
const expapp = require("express")()
this.window
app.on("ready", () => {
this.window = new BrowserWindow({webPreferences:{ nodeIntegration: true }})
this.window.loadURL("https://www.google.com.tr")
expapp.get("/", (req,res) => {
res.render("index.ejs")
})
/* Sayfayı geri al */
expapp.get("/back", (req,res) => {
this.window.selectPreviousTab()
res.send("ok")
})
})
expapp.listen(1661, () => { console.log("1661 portu üzerinden dinleniyor") })
当我用快递“ / back”去这条路线时,出现此错误
TypeError: this.window.selectPreviousTab is not a function
at C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\app.js:15:21
at Layer.handle [as handle_request] (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\index.js:275:10)
at expressInit (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (C:\Users\GreXLin85\Desktop\Projelerim\PC\xx\node_modules\express\lib\router\layer.js:95:5)
答案 0 :(得分:0)
您应该阅读有关电子中的main
和renderer
过程的信息:
https://www.electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes
在main
进程中,您没有全局window
变量:main
进程是node
进程,而不是浏览器。
并且BrowserWindow
类没有.selectPreviousTab()
方法-它不是NSWindow
,并且您不是在Swift
中编写本机代码。您应该使用electron
/ js
文档而不是native/Swift
开发electron
应用的文档。
electron
是用于使用节点和铬在JS
中编写桌面应用程序的框架/平台,它不是本机框架。< / p>