无法在渲染过程Electron上连接到NeDB [英] Can't connect to NeDB on render process Electron

查看:139
本文介绍了无法在渲染过程Electron上连接到NeDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将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?

GitHub代码

推荐答案

您可以通过在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

ipcRenderer未从主进程接收消息

这篇关于无法在渲染过程Electron上连接到NeDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆