1、安装@electron/remote
npm install --save @electron/remote 或者 cnpm install --save @electron/remote 或者 yarn add @electron/remote
2、主进程中配置启用 remote 模块
const remote=require(’@electron/remote/main’) remote.initialize() remote.enable(mainWindow.webContents);
主进程配置详细代码
const remote=require(’@electron/remote/main’) remote.initialize() const mainWindow = new BrowserWindow({ width: 800, height: 600, }); //启用 Remote 模块 remote.enable(mainWindow.webContents);
3、渲染进程引入 remote 模块使用
const { BrowserWindow } = require("@electron/remote")
渲染进程代码:
const btn = document.querySelector('#btn'); const path = require('path'); const { BrowserWindow } = require("@electron/remote") btn.onclick = () => { win = new BrowerWindow({ width: 300, height: 200, frame: false, transparent: true // fullscreen:trues }) win.loadURL(path.join('file:', __dirname, 'news.html')); win.on('close', () => { win = null }); }
留下您的脚步
最近评论