How to show an open file native dialog with Electron?

后端 未结 2 1171
眼角桃花
眼角桃花 2021-01-12 00:30

I am trying to add functionality to my Electron app that will allow users to open a file in the app, specifically plain text files. After looking at the Electron documentati

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 01:15

    const {dialog} = require('electron').remote;
    
    document.querySelector('#selectBtn').addEventListener('click', function (event) {
        dialog.showOpenDialog({
            properties: ['openFile', 'multiSelections']
        }, function (files) {
            if (files !== undefined) {
                // handle files
            }
        });
    });
    

提交回复
热议问题