繁体   English   中英

从BrowserWindow电子类扩展时出错

[英]Error when extending from BrowserWindow electron class

我使用https://github.com/SimulatedGREG/electron-vue模板创建了vue电子模板。 在主流程index.js旁边,我创建了一个文件MainWindow.js ,其中包含以下代码:

import { BrowserWindow } from 'electron';

export class MainWindow extends BrowserWindow {
  constructor(url) {
    super({
      height: 500,
      width: 300,
      frame: false,
      resizable: false,
      show: false,
      webPreference: { backgroundThrottling: false }
    });
    console.log('constructor called.');

    // this.loadURL(url);
    this.on('blur', this.onBlur.bind(this));
  }

  onBlur() {
    this.hide();
  }
}

现在,当我尝试创建MainWindow的实例时,出现以下错误:

Requires constructor call

function createWindow() {
  /**
   * Initial window options
   */
  mainWindow = new MainWindow();

  mainWindow.loadURL(winURL);

  mainWindow.on('closed', () => {
    mainWindow = null;
  });
}

我不知道为什么会发生此错误,因为我正确使用了new

您不应该从BrowserWindow继承。 当前不支持。

查看:

https://github.com/electron/electron/issues/23

https://github.com/electron/electron/issues/8898

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM