Comments (6)
没有跨域的,用 axios 或 fetch 在渲染进程中写
有跨域的,用 axios 或 node-fetch 在主进程中写
from electron-vite-vue.
好的,感谢大佬解答
from electron-vite-vue.
有三种方案,不知道大佬推荐用哪一种
在
preload
中使用contextBridge,然后传递给渲染进程使用netapi,request库或者fetch
//使用fetch,然后渲染进程使用window.getData.request(url); contextBridge.exposeInMainWorld("getData", { async request(url: RequestInfo, init: RequestInit) { const res = await fetch(url, init); return await res.json(); }, });
想请教一下你的contextBridge.exposeInMainWorld是写在preload.ts文件里面吗?然后怎么预加载的.我用用下面的方式加载不了preload文件里面的代码。
want to know where your contextBridge.exposeInMainWorld save. is it in preload.ts file? then how to preload it, i use the way below, but it doesn't load it actually.
const createWindow = () => {
const win = new BrowserWindow({
width: 1600,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: 'electron/preload.ts', // path.join(__dirname, 'preload.js') <- not build in dist, so failed too.
},
});
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
} else {
// load your file
win.loadFile(path.join(__dirname, "../dist/index.html"));
}
win.webContents.openDevTools();
};
from electron-vite-vue.
使用 contextBridge.exposeInMainWorld
需要关闭 nodeIntegration
from electron-vite-vue.
使用
contextBridge.exposeInMainWorld
需要关闭nodeIntegration
关闭了之后要怎么preload那个文件..我那个preload的地址一直加载不成功。然后暴露不了自定义的api
from electron-vite-vue.
Demo 不可能加载不到 preload 你还是改了什么东西。去看下实际生成的文件,这个问题不难多自己研究研究。
from electron-vite-vue.
Related Issues (20)
- 你好,在这个项目模板中怎么做窗口之间的通信呢? HOT 5
- 打包构建时报错 npm run build:win HOT 10
- 麻烦帮忙看一下。在生产环境启动后,页面空白。在开发环境是没问题的。 HOT 4
- [Help] windows安装包可以支持多语言吗 HOT 2
- 打包electron报x509: certificate has expired or is not yet valid HOT 2
- [Bug] The process not found. When closing app. HOT 1
- [Bug] 升级Electron v29后渲染进程ipcRender报错 HOT 4
- How to pack? HOT 3
- how is work HOT 2
- [Help] mysql2这个npm包无法被排除构建 HOT 4
- [Help] 希望加个eslint。谢谢 HOT 1
- [Bug] 修改renderer代码后,保存,F5可能没生效,关闭程序再次F5就好了
- [Help]如何打开一个新窗口并且使用vue-router跳转 HOT 2
- printWindow.webContents.print({ silent: true })[Help] the title of help wanted report HOT 1
- 有交流群吗或者有官网吗? HOT 1
- [Bug] Missing return statement in invoke method of preload script in Electron template HOT 1
- vite配置了base参数后,build之后找不到js文件 HOT 5
- [Bug] electron降级到22版本提示不支持require() of ES Module HOT 5
- 想要发布用户 客户在线热更新功能 HOT 1
- Can not build success cause of icon set HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-vite-vue.