试了 reply 发现子页面接管不到父页面传来的参数,最初在文档里找到webContents
主过程
main.js
ipc.on('new_win', (e, arg) => {
// 创立子页面
var main_new_win = new BrowserWindow({...})
main_new_win.on('ready-to-show', function () {main_new_win.webContents.send('data',arg.data); // 发送音讯
main_new_win.show() // 初始化后再显示})
main_new_win.on('closed', () => {main_new_win = null})
})
渲染过程
father.html
const ipc = require('electron').ipcRenderer;
function new_win(options){
var options = {
name:options.name || null,
title:options.title || '新窗口',
width:options.width || 450,
height:options.height || 500,
frame:options.frame=='hiden'?false:true,
data:options.data || null // 须要发送的数据
}
ipc.send('new_win',options);
}
child.html
const ipc = require('electron').ipcRenderer;
ipc.on('data', (e,arg) => {console.log(arg)
});