From fcb836a49205a837dd995aad37e5c7163ea938d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Tue, 2 Nov 2021 15:23:29 +0800 Subject: [PATCH] chore(docs): Communication --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 339f15c..20d6d1e 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,29 @@ ## Communication - All NodeJs、Electron API invoke passed `Preload script` + * **src/preload/index.ts** + + ```typescript + // --------- Expose some API to Renderer process. --------- + contextBridge.exposeInMainWorld('fs', fs) + contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer) + ``` + + * **typings/global.d.ts** + + ```typescript + interface Window { + fs: typeof import('fs') + ipcRenderer: import('electron').IpcRenderer + } + ``` + + * **src/render/main.ts** + + ```typescript + console.log('fs', window.fs) + console.log('ipcRenderer', window.ipcRenderer) + ``` ## Branchs - [ant-design-vue](https://github.com/caoxiemeihao/electron-vue-vite/tree/ant-design-vue) * [x] Use tsx