为什么我不能在preload.js中需要sqlite3?
这是我在电子应用中的preload.js文件
window.onload = () => {
const $ = require('jquery');
//const sqlite3 = require('sqlite3').verbose();
//const db = new sqlite3.Database(':memory:');
var form_div="";
document.querySelector("#ppage_btn").addEventListener("click"()={
//console.log("ppage_btn renderer file");
$('#form-div input').each(function() {
$(this).attr('value', $(this).val());
});
form_div = $("#form-div").clone();
var elements = document.getElementsByClassName("cats");
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
var divToPrint = document.getElementById("form-div");
var db_data = divToPrint.outerHTML;
db.serialize(function() {
db.run("CREATE TABLE invoices (codeblock TEXT)");
var stmt = db.prepare("INSERT INTO invoices VALUES (?)");
stmt.run(db_data);
stmt.finalize();
});
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
});
}
每当我删除这些行时, // const sqlite3 = require('sqlite3')。verbose(); // const db = new sqlite3.database(':memory:');
然后单击#PPAGE_BTN按钮以保存和打印表单,没有错误显示和整个应用程序窗口cruss。 是否有适当的方法在PRELOAD.JS文件中添加SQLITE3?
This is my preload.js file in electron application
window.onload = () => {
const $ = require('jquery');
//const sqlite3 = require('sqlite3').verbose();
//const db = new sqlite3.Database(':memory:');
var form_div="";
document.querySelector("#ppage_btn").addEventListener("click"()={
//console.log("ppage_btn renderer file");
$('#form-div input').each(function() {
$(this).attr('value', $(this).val());
});
form_div = $("#form-div").clone();
var elements = document.getElementsByClassName("cats");
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
var divToPrint = document.getElementById("form-div");
var db_data = divToPrint.outerHTML;
db.serialize(function() {
db.run("CREATE TABLE invoices (codeblock TEXT)");
var stmt = db.prepare("INSERT INTO invoices VALUES (?)");
stmt.run(db_data);
stmt.finalize();
});
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
});
}
Whenever i un-comment these lines
//const sqlite3 = require('sqlite3').verbose();
//const db = new sqlite3.Database(':memory:');
and click on #ppage_btn button to save and print the form ,no error shows and the whole app window crushes ..
is there any proper way to add sqlite3 in preload.js file ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论