亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

mainWindow 未定義 electron js

mainWindow 未定義 electron js

紅顏莎娜 2022-12-02 15:51:26
我在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 })    })})
查看完整描述

1 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

您在其中定義了它createWindow;在該功能之外無法訪問它。


所以返回它,然后在調用時捕獲它createWindow:


function createWindow () {

  // ...

  return mainWindow;

}


app.whenReady().then(() => {

    const mainWindow = createWindow()



查看完整回答
反對 回復 2022-12-02
  • 1 回答
  • 0 關注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號