前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Electron渲染进程与主进程进行通信

Electron渲染进程与主进程进行通信

作者头像
明知山
发布2021-12-13 10:27:33
6570
发布2021-12-13 10:27:33
举报

ipcMain

渲染进程

const { ipcRenderer } = require('electron')
ipcRenderer.send('login')  //发送 login 

主进程

import { ipcMain } from 'electron'
ipcMain.on('login', (event, arg) => {
	console.log(123)
}

更多ipcMain操作,参考文档地址

remote

remote在旧版本是内置的模块, 但是在新版本将被弃用,要用@electron/remote进行代替

	yarn add @electron/remote

主进程

	require('@electron/remote/main').initialize()
    webPreferences: {
      enableRemoteModule: true
    },

渲染进程使用

// 获取当前窗口属性
const { getCurrentWindow } = require('@electron/remote')

@electron/remote参考

渲染进程获取不到electron

vue.config.js

module.exports = {
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true
    }
  }
}

background.js设置

new BrowserWindow({
    width: 415,
    height: 450,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true
    },
  })
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-12-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ipcMain
  • remote
  • 渲染进程获取不到electron
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档