TypeError:无法读取属性' webContents'在Electron-dl中为null

时间:2018-01-11 21:21:21

标签: javascript npm javascript-events electron

我想下载文件并将其保存到所需的文件夹,但每次我收到以下错误。

Main.js

ipcMain.on('download-file', function (event, data) {
    console.log(data);
    download(BrowserWindow.getFocusedWindow(), data.url, {
        directory: "G:\\Orders\\"
    }).then(function (dl) {
        console.log(dl.getSavePath());
    }).catch(console.error);
});

错误

TypeError: Cannot read property 'webContents' of null
    at Promise (G:\fc-electron\node_modules\electron-dl\index.js:125:22)
    at Promise (<anonymous>)
    at module.exports.download (G:\fc-electron\node_modules\electron-dl\index.js:122:47)
    at EventEmitter.<anonymous> (G:\fc-electron\main.js:53:9)
    at emitTwo (events.js:125:13)
    at EventEmitter.emit (events.js:213:7)
    at WebContents.<anonymous> (G:\fc-electron\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:249:13)
    at emitTwo (events.js:125:13)
    at WebContents.emit (events.js:213:7)

任何有用的答案都将不胜感激。

0 个答案:

没有答案