【发布时间】:2020-03-17 10:12:38
【问题描述】:
我正在编写我的第一个电子应用程序,所以请宽容:)
当用户按下主窗口上的按钮时,应该会打开一个显示一些 json 字符串的新窗口。 此事件被 ipcMain 截获:
ipcMain.on("JSON:ShowPage", function(e, item) {
createJSONWindow(item);
})
这是我创建新窗口的函数:
function createJSONWindow(item) {
let jsonWin = new BrowserWindow({
width: 600,
height: 800,
center: true,
resizable: true,
webPreferences:{
nodeIntegration: true,
show: false
}
});
jsonWin.loadFile("jsonView.html");
ipcMain.on('JSON_PAGE:Ready', function(event, arg) {
jsonWin.webContents.send('JSON:Display', item);
})
jsonWin.once('ready-to-show',()=>{
jsonWin.show()
});
jsonWin.on('closed',()=>{
jsonWin = null;
});
}
现在我的问题是,当我打开多个JSONWindows 时,每个人都会收到JSON:Display 消息并更新其内容。他们不应该彼此独立工作吗? jsonWin 总是一个新的BrowserWindow,不是吗?
提前致谢。
【问题讨论】:
标签: javascript npm electron