我有一个电子应用程序与表格,将被用来获得一些信息。我没有可以发送数据的外部服务器或url,我需要获取表单数据并使用dexie.js和vue存储它们,我使用它们来拦截提交按钮上的单击事件。我不确定如何保存数据,这是因为我需要从表单中获取值,然后调用dexie来存储它们,我使用vue方法来管理单击,我使用document.forms来获取表单元素的名称和值,但这是一个糟糕的方法。有人能帮我找到一种方法来实现这一点吗?
//import Dexie from 'dexie';
const Dexie = require('dexie');
// Force debug mode to get async stacks from exceptions.
Dexie.debug = true; // In production, set to false to increase performance a little.
let db = new Dexie('clients');
db.version(1).stores({
websites: "++id,client_name,hosting_provider,website_domain,panel_user,panel_pwd,db_host,db_name,db_user,db_pwd,wp_user,wp_pwd"
});
$(document).ready(function(){
var myapp = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
},
methods: {
saveData(){
//var form = document.getElementById('client-info') //document.forms;;
var form = $('#client-info').serialize();
console.log(form);
//var formData = new FormData(form);
//console.log(formData);
// $.each( form[0].elements, function(i, index){
// console.log( index );
// console.log( form[0].elements[i].name, form[0].elements[i].value );
// // or make a new one
// db.clients.add({
// form[0].elements[i].name: form[0].elements[i].value
// });
// });
//console.log(Dexie);
//console.log(db);
}
}
});
console.log(myapp);
});注意:现在我已经注释了代码,因为它不会工作,它不会保存数据。
发布于 2020-03-23 19:36:58
您可能想尝试将Dexie代码添加到主进程,它在传统的web术语中充当后端,并通过ipcRenderer将表单发送到主进程(类似于我在here上提出的内容)。
https://stackoverflow.com/questions/60796391
复制相似问题