主题
Dialog
以下是自己常用的,详细请看
引入包
主进程
js
const { dialog } = require('electron')渲染进程
js
const { dialog } = require('electron').remote选择文件 —— showOpenDialog
- 参数:
options: Objecttitle: string: 标题properties: string[]:特性值openFile:可打开文件multiSelections:可多选
filters: {name: string, extensions: string[]}[]:显示给用户的文件name:文件类型名extensions:后缀名,不带点(.)
- 返回:
Promise- 成功返回
{ filePaths: string[] } - 失败返回
undefined
- 成功返回
js
dialog.showOpenDialog({
title: '选择导入的 Markdown 文件',
properties: ['openFile', 'multiSelections'],
filters: [
{name: 'Markdown files', extensions: ['md']}
]
}).then( ({ filePaths }) => { /* ... */ })保存文件 —— showSaveDialog
- 参数:
options: Objecttitle: string: 标题defaultPath: string:默认打开文件夹路径
- 返回:
Promise- 成功返回
{ filePath: string } - 失败返回
undefined
- 成功返回
js
dialog.showOpenDialog({
title: '请选择要保存的文件夹',
defaultPath: __dirname
}).then( ({ filePath }) => { /* ... */ })消息框 —— showMessageBox
- 参数:
options: Objecttype: string:"none","info","error","question"或者"warning"title: string:标题message: string:内容
