background.ts中的webPreferences配置如下
const win = new BrowserWindow({
width: 920,
height: 640,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
// nodeIntegration: (process.env
// .ELECTRON_NODE_INTEGRATION as unknown) as boolean,
nodeIntegration: true,
contextIsolation: false,
},
})
同时在vue.config.js中配置如下
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
},
},
这样就可以在vue文件中直接引用electron模块了
import { ipcRenderer } from 'electron'
Web前端(W3Cways.com) - Web前端学习之路