Goal : When using electron-vue to develop a desktop application, a new window is created. It is hoped that the value of the main window can be used in the new window, which involves the transfer of values between windows.
Implementation :
- The rendering process of window A sends a message to the main process
const sendMsgMain = (msg) => {
ipcRenderer.send('sendMsgMain', msg)
}
- After the main process receives the message, it sends the message to the rendering process of window B.
ipcMain.on('sendMsgMain', (e, msg) => {
childWin.webContents.send('msgFromMain', msg) // childWin为B窗口
})
- Window B rendering process receives main process messages
const getMsgChild = () => {
ipcRenderer.on('msgFromMain', (e, message) => {
console.log(message)
});
}
- Execute getMsgChild in the component loaded in window B to monitor, create a button click event in the component loaded in window A, and trigger sendMsgMain.