久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ElectronJS:未捕獲的類型錯誤:無法讀取屬性“Brow

ElectronJS: Uncaught TypeError: Cannot read property quot;BrowserWindowquot; / quot;getCurrentWindowquot; of undefined(ElectronJS:未捕獲的類型錯誤:無法讀取屬性“BrowserWindow/“獲取當前窗口未定義的) - IT屋-程序員軟
本文介紹了ElectronJS:未捕獲的類型錯誤:無法讀取屬性“BrowserWindow"/“獲取當前窗口"未定義的的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

首先,我知道這是一個只有初學者才會問的問題,但是在經歷了 50 多種不同的解決方案、卸載 npm 和安裝 yarn 之后,我不得不問這個令人難以置信的愚蠢問題.為什么這不起作用?我想使用 ElectronJS 實現一個簡單的標題欄,我遇到的問題是按鈕(關閉/最小化/最大化)不起作用.我收到的錯誤如下:

First of all, I know that this is a question only a beginner would ask, but after going through more than 50 different solutions, uninstalling npm and installing yarn I have to ask this incredible dumb question. Why doesnt this work? I want to implement a simple titlebar using ElectronJS, the problem that I have is that the buttons (Close / Minimize / Maximize) do not work. The errors that I receive are the following:

最小化錯誤:titlebar.js:16 Uncaught TypeError: Cannot read property 'BrowserWindow' of undefined at HTMLButtonElement.maximizeApp (titlebar.js:16)

最大化錯誤:titlebar.js:16 Uncaught TypeError: Cannot read property 'BrowserWindow' of undefined at HTMLButtonElement.maximizeApp (titlebar.js:16)

退出錯誤:titlebar.js:21 Uncaught TypeError: Cannot read property 'getCurrentWindow' of undefined at HTMLButtonElement.quitApp (titlebar.js:21)

我用來控制它的 JavaScript 文件稱為 titlebar.js.就是這樣:

The JavaScript file that I use to control this is called titlebar.js. This is it:

const remote_v = require("electron").remote;

var minimize_v = document.getElementById("minimize");
var maximize_v = document.getElementById("maximize");
var quit_v = document.getElementById("quit");

minimize_v.addEventListener("click",minimizeApp);
maximize_v.addEventListener("click",maximizeApp);
quit_v.addEventListener("click",quitApp);

function minimizeApp(){
  remote_v.BrowserWindow.getFocusedWindow().minimize();
}

function maximizeApp(){
  remote_v.BrowserWindow.getFocusedWindow().maximize();
}

function quitApp(){
  remote_v.getCurrentWindow().close();
}

由于許多其他類似問題的修復都在渲染過程中,這是 HTML 文件:

Since many of the fixes for other problems like this is in the render process, this is the HTML File:

<!DOCTYPE html>
    <head>
        <title>Visionizer</title>

        <link rel="stylesheet" href="css/editor.css">
        <link rel="stylesheet" href="css/titlebar.css" >
    </head>
    <body>
        <div class="container">         
            <div class="titlebar titlebarStyle">  
                <div class="windowTitle"> Visionizer </div>
                <div class="windowControls windowControlsStyle">
                    <button id="minimize">-</button>
                    <button id="maximize">[]</button>
                    <button id="quit">x</button>
                </div>
            </div>
            <div class="editorScreen">
            </div>
        </div>
        <script src="js/titlebar.js"></script>
    </body>
</html>

關于這個的奇怪之處在于,經過多次嘗試,我決定從 github 的教程中復制代碼,我認為我的代碼中可能有一個錯誤,我太笨了,看不到.它仍然沒有運行.我使用 npm 卸載了該軟件包,并使用 yarn global add electron@latest 使用 yarn 安裝了它,因為有人建議這樣做.

The weird thing about this is that, after much trying, I decided to copy the code from the tutorial from github, I thought that there may have been an error in my code that I was too dumb to see. It still didn't run. I uninstalled the package with npm and installed it with yarn using yarn global add electron@latest since some people suggested this.

我根本不知道這是否重要,但我也會從下面的 main.js 文件中復制我的代碼,因為我想確保我包含了所有內容:

I do not know whether this is important at all, but I will also copy my code from the main.js-file below since I want to be sure that I included everything:

const { app, BrowserWindow } = require('electron')

function createWindow () {
  const win = new BrowserWindow({
    width: 900,
    height: 800,
    minHeight: 650,
    minWidth: 600,
    frame: false,
    webPreferences: {
      nodeIntegration: true
    }
  })

  win.loadFile('editor.html')
  win.webContents.openDevTools()
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})

這是 package.json 文件:

And here is the package.json file:

{
  "dependencies": {
    "electron": "^11.0.2"
  },
  "name": "*******",
  "version": "1.0.0",
  "description": "**********",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },  
  "author": "************",
  "license": "MIT"
}

網上的一些問題回答說項目啟動錯誤,我聽從了他們的建議,我使用yarn start命令啟動我的項目

Some questions on the internet were answered by saying that the project was started wrongly, I followed their advice, I start my projects using the yarn start command

感謝您閱讀本文.

推薦答案

看起來你的 remote 模塊是 undefined.

It looks like your remote module is undefined.

您需要設置 enableRemoteModule: true 在主窗口的 webPreferences 中,或者更好的是,完全廢棄 remote 并從主進程中執行這些操作.

You'd want to set enableRemoteModule: true in your main window's webPreferences, or better yet, scrap remote altogether and do these operations from the main process.

remote 模塊在 中被禁用電子 10.

這篇關于ElectronJS:未捕獲的類型錯誤:無法讀取屬性“BrowserWindow"/“獲取當前窗口"未定義的的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 亚洲日本三级 | 91小视频 | 99久久精品国产一区二区三区 | 日韩av在线一区二区 | 欧美日韩在线一区二区 | 91精品在线看 | 精品亚洲视频在线 | 欧美在线视频a | 国产精品91久久久久久 | 激情五月婷婷综合 | 久久精品二区 | 国产美女永久免费无遮挡 | 国产一级片一区二区三区 | 精品视频免费在线 | 亚洲欧美中文日韩在线v日本 | 伦理午夜电影免费观看 | 久久久精彩视频 | 一本大道久久a久久精二百 国产成人免费在线 | 久久久久一区 | 激情综合五月 | 久久综合一区 | 99久久久无码国产精品 | 亚洲国产精品一区二区久久 | 久久毛片网站 | www国产亚洲精品久久网站 | 欧美理论| 欧美一级高潮片免费的 | 免费视频久久久久 | 成人在线一区二区三区 | 日韩三级电影一区二区 | 天天拍天天操 | 国产一级在线观看 | 欧美中文一区 | 高清视频一区 | 国产四区 | 国产一区2区 | 久久久久中文字幕 | 亚洲成年人免费网站 | www国产成人免费观看视频,深夜成人网 | 亚洲一区二区三区四区五区午夜 | 免费成人毛片 |