gpt4 book ai didi

vue.js - 在Electron和Vue中加载预加载脚本

转载 作者:行者123 更新时间:2023-12-03 12:22:29 24 4
gpt4 key购买 nike

我正在使用Vue CLI 3和vue-cli-plugin-electron-builder打包我的Vue Electron应用程序,但无法获得preload.js脚本进行 Electron 工作。

主窗口

win = new BrowserWindow({
width: 800,
height: 600
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, "/../src/preload.js") // works but window.electron.dialog in undefined
}
});

preload.js
const { dialog } = require("electron");

window.electron = {};
window.electron.dialog = dialog;

我的Vue组件中 window.electron.dialog始终是未定义的-导入显然无法正常工作。注意 window.electron定义正确。我肯定错过了什么。

最佳答案

将以下行添加到文件vue.config.js中,如果该文件不存在,请在项目的根文件夹中创建一个

module.exports = {
//...
pluginOptions: {
electronBuilder: {
preload: 'src/preload.js',
// Or, for multiple preload files:
// preload: { preload: 'src/preload.js', otherPreload: 'src/preload2.js' }
}
}
//...
}
查看文档以了解更多 #preload-files

关于vue.js - 在Electron和Vue中加载预加载脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56478000/

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