-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请教一下,electron中请求接口数据应该怎么写? #67
Comments
没有跨域的,用 axios 或 fetch 在渲染进程中写 |
好的,感谢大佬解答 |
想请教一下你的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();
}; |
使用 |
关闭了之后要怎么preload那个文件..我那个preload的地址一直加载不成功。然后暴露不了自定义的api |
Demo 不可能加载不到 preload 你还是改了什么东西。去看下实际生成的文件,这个问题不难多自己研究研究。 |
在
preload
中使用contextBridge,然后传递给渲染进程使用netapi,request库或者fetch
在渲染进程使用类似axios,fetch的请求库
这个方法会有跨域的问题
使用ipc通信
我现在用的第一种方法,不知道大佬推荐用哪一种方法?也许可以在模板里写个例子?
The text was updated successfully, but these errors were encountered: