1? ? 渲染進程調(diào)用主進程得方法
?下面是渲染進程得代碼:
let { ipcRenderer} = require( 'electron' );
ipcRenderer.send( 'xxx' ); //渲染進程中調(diào)用
下面是主進程得代碼:
var { ipcMain } = require( 'electron' );
?ipcMain.on("xxx",function () { } )
? ?2 渲染進程與渲染進程之間的傳值
使用remote.BrowserWindow在某個渲染進程中打開一個新窗口,并向新窗口中傳值
xxxrWindow = new remote.BrowserWindow( {
webPreferences: {
nodeIntegration: true
},
show: true
} );
xxxrWindow.webContents.on( 'did-finish-load', () => {
xxxrWindow.webContents.send( "data", JSON.stringify(passInfo) );
remote.getCurrentWindow().close();//關(guān)閉當(dāng)前窗口
} );
然后在新窗口中html開始Script標(biāo)簽內(nèi)加入接收監(jiān)聽代碼
//數(shù)據(jù)監(jiān)聽
const ipc = require('electron').ipcRenderer;
ipc.on('data', (e,arg) => {
console.log("+++++++++++++++uu+++++++++++++++++++++++++");
console.log(arg)
});
注意 注意? 注意: 消息發(fā)送后,才能關(guān)閉當(dāng)前窗口,否則 打開的新窗口是接收不到消息的
也就是remote.getCurrentWindow().close();? 這行代碼要寫在上面的回調(diào)里面,保證代碼發(fā)送完畢后,才關(guān)掉當(dāng)前窗口,如果這行代碼寫在外面,窗口會先于代碼發(fā)送關(guān)掉,這樣代碼發(fā)送就沒執(zhí)行文章來源:http://www.zghlxwxcb.cn/news/detail-607108.html
FR:hunkXu文章來源地址http://www.zghlxwxcb.cn/news/detail-607108.html
到了這里,關(guān)于Electron 主進程和渲染進程傳值及窗口間傳值的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!