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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

    c. 渲染進程 new.js

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

    總結

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

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。