为什么我不能在preload.js中需要sqlite3?

发布于 2025-02-08 10:18:23 字数 1348 浏览 2 评论 0原文

这是我在电子应用中的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文