2016-12-15 28 views
1

主进程打开到渲染器需要访问的服务的连接。电子:renderer访问主进程?

这可能吗?

我试过声明global.thingexports.thing,并且具有渲染require('electron').remote.thing - 这里就是一个函数或标量 - 但没有运气。

回答

4

你可以做更多的方式:

1)进程之间通信的IPCipcRenderer.sendSync功能,即要求主工艺要求的数据和等待返回值。 https://github.com/electron/electron/blob/master/docs/api/ipc-renderer.md

2)使用出口以正确的方式,因此:

的主要工序:

exports.functionName = functionName; 

中渲染:

var functionName = remote.require('./main').functionName; 
+0

试过后者 - 现在我明白了错字:谢谢。 – LeeGee

+0

@ emish89:你可以请看看http://stackoverflow.com/questions/41485770/access-a-function-in-main-window-from-renderer-process-in-electron?noredirect=1#comment70204002_41485770 –