electron 网页和主进程通讯
前端网页
import { RxIpc } from 'rx-ipc-electron/lib/rx-ipc'; export const IsElectron = window.navigator.userAgent.toLowerCase().indexOf('electron') !== -1; export function ajax(config) { if (!IsElectron) return Promise.reject('only for electron'); const { ipcRenderer } = eval(`require('electron')`); const rxIpc = new RxIpc(ipcRenderer); return new Promise((resolve, reject) => { rxIpc.runCommand('ajax', null, config).subscribe(resolve, reject); }); } window['test1'] = async function test1() { const url = 'https://www.baidu.com/s'; const params = { wd: 1 }; const rsp = await ajax({ url, method: 'get', params, }); console.log(rsp); }
electron进程
import rxIpc from 'rx-ipc-electron/lib/main'; import { Observable } from 'rxjs'; import axios from 'axios'; rxIpc.registerListener('ajax', config => { return Observable.from(axios(config)); });
相关推荐
游走的豚鼠君 2020-11-10
sanallen 2020-07-04
electronvolt 2020-07-04
sanallen 2020-06-14
moyigg 2020-06-09
疯狂老司机 2020-06-07
zhujuyu 2020-06-06
moyigg 2020-06-01
zhujuyu 2020-05-30
viewerlin 2020-05-29
zhujuyu 2020-05-28
yanchuncheng 2020-05-12
Trustport 2020-05-06
chenyijun 2020-05-05
electronvolt 2020-05-04
游走的豚鼠君 2020-05-01
electronvolt 2020-04-21
游走的豚鼠君 2020-04-18