Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电子中未定义的模板常数_Javascript_Electron - Fatal编程技术网

Javascript 电子中未定义的模板常数

Javascript 电子中未定义的模板常数,javascript,electron,Javascript,Electron,我正在完成我在Electron上的第一个应用程序,我是一名初级Web开发人员,如果这是一个简单的错误,请原谅,或者你发现了一些你认为可以做得更好的东西。但基本上,我正在macOS上构建一个基本菜单,这样我就可以在打包后拥有复制/粘贴功能。现在,我遵循了中的文档,进行了一些调整以满足我的需要,但在运行时似乎遇到了问题,错误是: Uncaught Exception: TypeError: Cannot read property 'buildFromTemplate' of und

我正在完成我在Electron上的第一个应用程序,我是一名初级Web开发人员,如果这是一个简单的错误,请原谅,或者你发现了一些你认为可以做得更好的东西。但基本上,我正在macOS上构建一个基本菜单,这样我就可以在打包后拥有复制/粘贴功能。现在,我遵循了中的文档,进行了一些调整以满足我的需要,但在运行时似乎遇到了问题,错误是:

    Uncaught Exception:
    TypeError: Cannot read property 'buildFromTemplate' of undefined
    at EventEmitter.createWindow (/Users/Jay/Desktop/click_palette_release/app/main.js:73:22)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
这对我来说意味着“模板”没有定义?但是我在第70行的顶部用const定义了它。我错过了什么?这件事让我挠头已经有一段时间了

const template = [
{
    label: 'Edit',
    submenu: [
      {
        role: 'copy'
      },
      {
        role: 'paste'
      },
    ]
}];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
第73行是
const menu=menu.buildFromTemplate(模板)

提前谢谢

完整代码:

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

const Configstore = require('configstore');
const pkg = require(__dirname + '/init.json');
const sysconf = new Configstore(pkg.name);

var Menu = require("electron").menu;
let mainWindow;

function createWindow(){
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.

    if (sysconf.get('bounds')){
        var bounds = sysconf.get('bounds');
    } else {
        var bounds = {'x':'', 'y':'', 'width':'400', 'height':'125'}
    }

    // Create the browser window.
    mainWindow = new BrowserWindow({
        x: bounds.x,
        y: bounds.y,
        width: 400,
        height: 90,
        //'titleBarStyle': 'hidden',
        title: 'ClickPalette',
        backgroundColor: '#fff',
        frame: false
    });

    mainWindow.setResizable(false);
    mainWindow.setAlwaysOnTop(true);
    mainWindow.loadURL('file://' + __dirname + '/index.html');
    mainWindow.setMenu(null);

    //mainWindow.webContents.openDevTools();

    mainWindow.on('close', function(e) {
        var bounds = mainWindow.getBounds();
        sysconf.set({'bounds' : bounds});
    });

    // Emitted when the window is closed.
    mainWindow.on('closed', function() {
        mainWindow = null;
    });

    //Settings / Manager
    var manageWindow = new BrowserWindow({
        width: 400,
        height: 400,
        show: false
    });

    manageWindow.loadURL('file://' + __dirname + '/manage.html');
    //manageWindow.webContents.openDevTools();

    const template = [
    {
        label: 'Edit',
        submenu: [
          {
            role: 'copy'
          },
          {
            role: 'paste'
          },
        ]
    }];
    const menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);

};

// Load mainWindow
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

//Show window
app.on('activate', function (e) {
    if (mainWindow === null) {
        createWindow();
    }
});
已解决
我使用的是
const Menu=require('electron')。Menu但是M in菜单应该是大写的:
const menu=require('electron')。menu

无法读取未定义的属性“buildFromTemplate”
表示
菜单
未定义
。不是
模板
。好的,好的,这样更有意义。我会调查的,谢谢!查看如何获取对
菜单的引用
。是的,所以我在做
const Menu=require('electron')。Menu
M on菜单需要大写:
const menu=require('electron')。menu