我正在使用 Electron 并试图在用户单击按钮时打开文件浏览器。在渲染过程中,我试图像这样包含 elctron.dialog 包。
const dialog = require( 'electron' ).dialog;
console.log( dialog );
但是控制台日志的结果是 undefined
我绝对确定我在渲染过程中,所以我不确定为什么这不起作用。文档表明这是正确的做事方式,但它似乎不起作用。
这是我的package.json
文件
{
"name": "my-app",
"version": "0.1.0",
"main": "./main.js",
"scripts": {
"start": "electron ."
},
"dependencies": {
"electron": "^0.4.1"
}
}
这是我的main.js
文件
'use strict';
var app = require( 'app' );
var BrowserWindow = require( 'browser-window' );
var ipc = require( 'ipc' );
var mainWindow = null;
app.on(
'ready', function () {
mainWindow = new BrowserWindow(
{
frame : true,
height: 700,
width : 500
}
);
mainWindow.loadUrl( 'file://' + __dirname + '/app/index.html' );
mainWindow.openDevTools();
mainWindow.on(
'closed', function () {
mainWindow = null;
}
);
}
);
ipc.on(
'close-main-window', function () {
app.quit();
}
);
这是渲染过程文件
// Add your index.js code in this file
var ipc = require( 'ipc' );
const dialog = require( 'electron' ).dialog;
console.log( dialog );
这是控制台
这是不正确的吗?
最佳答案
在Renderer进程上,必须使用Remote模块。
const dialog = require('electron').remote.dialog
关于javascript - 未定义从渲染过程中要求 Electron 对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637201/