无法在渲染过程Electron上连接到NeDB [英] Can't connect to NeDB on render process Electron
问题描述
我在将NeDB连接到我的反应电子应用程序时遇到问题.现在,我在项目上安装了NeDB,并将其连接到 electron.js
文件.
I have problem with connect NeDB to my react-electron app. Now I install NeDB on my project and connect him to electron.js
file.
const Datastore = require('nedb');
let db = {};
db.students = new Datastore({
filename:'./students.json',
autoload: true
})
db.students.insert({name : "Putin V.V.", year: 1952});
现在,我需要将此数据库连接到我的app.js文件.如何在渲染部件上使用此文件?
Now I need connect this db to my app.js file. How I can manipulate with this file on render part?
推荐答案
您可以通过在Electron上使用ipc来实现您的想法.我以前发布了答案.请检查以下内容.
You can achive your idea by using ipc at Electron. I posted an answer before. Please check the below.
但这是先决条件.
创建 BrowserWindow
时应启用节点集成所以在您的代码上,应该是这样
You should enable the nodeintegration when you are creating the BrowserWindow
So at your code, it should be like this
mainWindow = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 900,
minHeight: 600,
show: false,
icon: "",
webPreferences: {
nodeIntegration: true
}
});
此后,您可以在renderer(您的react应用)上使用此ipcRenderer.如果您未设置此选项.然后您将面临以下类似问题
After this, you can use this ipcRenderer at renderer(your react app). If you don't set this option. Then you will face the similar issue as below
这篇关于无法在渲染过程Electron上连接到NeDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!