请指导我通过一个完整的过程,我连接我的电子应用程序与sqlite3。因为我的电子js中有很多问题。谢谢。
Main.js:
const{app,BrowserWindow,ipcMain}=require("electron");
app.on("ready",createWindow);
const si = require("systeminformation");
require("electron-reload")(__dirname);
function createWindow()
{
const window = new BrowserWindow({
width: 800,
height:600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
window.webContents.openDevTools();
window.loadFile(__dirname+ "/index.html");
}
ipcMain.on("get-cpu-usage",(events,args)=>{
console.log(args);
});renderer.js:
const{ipcRender} = require("electron")
const os=require("os");
const cpuName=document.getElementById("cpu-name");
const cpuCores =document.getElementById("cores");
const cpuUsage =document.getElementById("cpu-usage");
const cpus=os.cpus();
cpuName.innerText=`CPU: ${cpus[0].model}`;
cpuCores,innerText=`Cores Available: ${cpus.length}`;
setInterval(() =>{
console.log("sending message to get cpu stats")
ipcRender.send("get-cpu-usage", "Hello sheraz The render process")
},2000)发布于 2021-11-03 15:01:47
到目前为止,与电子一起使用SQLite的最简单的方法是使用电子生成器。
首先,在package.json中添加一个postinstall步骤:
"scripts": {
"postinstall": "install-app-deps"
...
}然后安装必要的依赖项并构建:
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall电子构建器将为您的平台构建本机模块,并为电子绑定提供正确的名称;然后,您可以按照正常的代码要求它。
https://stackoverflow.com/questions/69827056
复制相似问题