我在ElectronJS中制作了一個應用程序,并嘗試在事件中加載不同的 html 文檔。但是當我嘗試這樣做時,出現了這個錯誤(見下圖)那么,我做錯了什么,還是有不同的方法..?這是我的代碼:const { app, BrowserWindow, ipcMain } = require('electron')const path = require('path');function createWindow () { // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 600, icon: "icon.png", webPreferences: { nodeIntegration: true } }) mainWindow.loadFile("index.html");}app.whenReady().then(() => { createWindow() app.on('activate', function () { if(BrowserWindow.getAllWindows.length === 0) createWindow() })}).catch(err => console.log(err))app.on('window-all-closed', function () { if(process.platform !== 'darwin') app.quit()})ipcMain.on("login", (event, data) => { Authenticator.getAuth(data.u, data.p).then(() => { event.sender.send('done') mainWindow.loadURL(path.join(__dirname, "home.html")) }).catch((err) => { event.sender.send("err", { er: err }) })})
mainWindow 未定義 electron js
紅顏莎娜
2022-12-02 15:51:26