gpt4 book ai didi

javascript - 未定义从渲染过程中要求 Electron 对话

转载 作者:可可西里 更新时间:2023-11-01 01:36:30 31 4
gpt4 key购买 nike

我正在使用 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 

更多信息:
Electron Dialog API
Electron Remote API

关于javascript - 未定义从渲染过程中要求 Electron 对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637201/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com