日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

electron 主进程与渲染进程 渲染进程与渲染进程 之间的通信

發(fā)布時(shí)間:2023/11/30 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 electron 主进程与渲染进程 渲染进程与渲染进程 之间的通信 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
  • 主進(jìn)程與渲染進(jìn)程之間的通信
  • 這是渲染進(jìn)程 // 渲染進(jìn)程執(zhí)行主進(jìn)程里面的方法,主進(jìn)程給渲染進(jìn)程反饋處理結(jié)果 。 var sendreplayDom=document.querySelector('#sendreplay'); sendreplayDom.onclick=function(){// alert('1213')//渲染進(jìn)程給主進(jìn)程廣播數(shù)據(jù)ipcRenderer.send('sendreplay','this is renderer aaa'); } //接收主進(jìn)程廣播的事件 ipcRenderer.on('replay',function(event,data){console.log(data); }) 這是主進(jìn)程 //接收廣播 并且返回處理結(jié)果 ipcMain.on('sendreplay',function(event,data){console.log(data);// console.log(event);//主進(jìn)程給渲染進(jìn)程廣播數(shù)據(jù)event.sender.send('replay','ok haha'); })
  • 渲染進(jìn)程與渲染進(jìn)程之間的通信
  • a.渲染進(jìn)程 openWindows.js btn.onclick=function(){// alert('點(diǎn)擊了');var aid='12345678';ipcRenderer.send('openWindow',aid); } //接收news 傳過(guò)來(lái)的數(shù)據(jù) ipcRenderer.on('toIndex',function(event,data){console.log(data) }) b.主進(jìn)程 ipcMain.js ipcMain.on('openWindow',function(event,aid){//1.獲取當(dāng)前窗口的對(duì)象 var winId=BrowserWindow.getFocusedWindow().id;//調(diào)用 BrowserWindow打開新窗口win=new BrowserWindow({width:400,height:300,webPreferences:{nodeIntegration: true}// frame:false,// fullscreen:true})win.loadURL(path.join('file:',__dirname,'../news.html'));//開啟新窗口的調(diào)試模式win.webContents.openDevTools();//通過(guò)win.webContents.send把當(dāng)前數(shù)據(jù)廣播給 news進(jìn)程win.webContents.on('did-finish-load',function(){win.webContents.send('toNews',aid,winId);})win.on('closed',()=>{win=null;}) })

    c. 渲染進(jìn)程 new.js

    ipcRenderer.on('toNews',function(event,aid,winId){// winId 第一個(gè)窗口的id//獲取 對(duì)應(yīng)id的窗口console.log(aid);var firstWin=BrowserWindow.fromId(winId);firstWin.webContents.send('toIndex','this is news'); })

    總結(jié)

    以上是生活随笔為你收集整理的electron 主进程与渲染进程 渲染进程与渲染进程 之间的通信的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。