【问题标题】:How to send data from one Electron window to another with ipcRenderer using vuejs?如何使用 vuejs 使用 ipcRenderer 将数据从一个 Electron 窗口发送到另一个窗口?
【发布时间】:2019-02-11 22:38:47
【问题描述】:

我有一个组件:

openNewWindow() {
    let child = new BrowserWindow({

        modal: true,
        show: false, 

    });
    child.loadURL('http://localhost:9080/#/call/' + this.chatEntityId + '?devices=' + JSON.stringify(data));
    child.on('close', function () { child = null; });

    child.once('ready-to-show', () => {
        child.show();
    });

    child.webContents.on('did-finish-load', () => {
        console.log("done loading");
        ipcRenderer.send('chanel',  "data");
    });
}

然后在子窗口组件中:

mounted() {
    ipc.on('chanel', (event, message) => {
       console.log(message);
       console.log(event);
    });
}

我在created()beforeCreate() 以及this.$nextTick(), withsetTimeout 中尝试了.on,但没有任何效果。

我不想发送一些字符串数据而是对象,但正如您所见,事件简单字符串 "data" 不起作用。我没有想法。

我可以看到,如果我这样做,这仅适用于发出来自的组件的父组件:

  1. 发送
  2. 在主进程中监听
  3. 发回event.sender

那么,问题是如何将任何形式的数据从一个窗口传递到另一个窗口?

【问题讨论】:

    标签: vuejs2 electron vuex vuex-modules


    【解决方案1】:

    好的,经过漫长的夜晚,解决后的早晨。

    1. 在某些 vuejs 组件中,例如对按钮单击的某些操作

    ipcRenderer.send('chanel', someData);

    1. 在主进程中

      ipcMain.on('chanel', (event, arg) => {
         let child = new BrowserWindow()
         // other stuff here
         child.loadURL(arg.url)
         child.on('show', () => {
              console.log("done loading");
              child.webContents.send('data',  arg);
         });
      })
      
    2. 在其他路由的 vuejs 组件中 arg.url

      mounted() {
          ipc.on('chanel', (event, message) => {
             console.log(message);
             console.log(event);
          });
      }
      

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多