用HTML和CSS和JS构建跨平台桌面应用程序的开源库Electron的介绍以及搭建HelloWorld:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106413828
Electron怎样进行渲染进程调试和使用浏览器和VSCode进行调试:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106414541
在上面搭建好项目以及知道怎样进行调试后,那么Electron有哪些常用的对话框。
打开文件对话框
首先在index.html中增加一个Button按钮,并添加id
<button id="openDialog">打开button>
然后在js中,通过id获取按钮并设置其点击事件
var btnOpenDialog=document.getElementById('openDialog');btnOpenDialog.onclick = OpenDialog;
这个对话框是从Electron的主线程上打开的。如果要使用渲染器进程中的对话框对象, 可以使用remote来获得
const {dialog} = require('electron').remote;
然后在上面的OpenDialog方法中
function OpenDialog(){
dialog.showOpenDialog({
title: "请选择您喜欢的文件", buttonLabel: "走你", filters: [ { name: 'Custom File Type', extensions: ['js', 'html', 'json'] }, ] }).then(result => {
console.log(result.canceled) console.log(result.filePaths) }).catch(err => {
console.log(err) })}