我正在创建一个发票应用程序,并且在我的SQlite数据库中添加了很多东西,但是没有出现问题,但是由于我的一张桌子而增加了总金额时遇到了问题。我对POST请求中的发票名称或付款金额没有任何问题,但是由于某些原因,当发送到服务器端时,应付总额变得不确定。
这是我的发票表POST的Express.js服务器代码:
let sql = `INSERT INTO invoices(name, user_id, paid, total_due, created) VALUES('${req.body.name}','${req.body.user_id}','${req.body.paid}','${req.body.total_price}',datetime('now', 'localtime'))`;
console.log(req.body.total_price, req.body.paid, req.body.name)
db.serialize(function() {
db.run(sql, function(err) {
if (err) {
return res.json({
status: false,
message: "There was an error creating invoice!"
});
}
这是我的Vue.js代码,用于将数据发送到服务器”
formData.append("name", this.invoice.name)
formData.append("item_id", item_id)
formData.append("description", description)
formData.append("quantity", quantity)
formData.append("price", price)
formData.append("paid", this.invoice.paid)
formData.append("total_due", this.invoice.total_price)
let user = JSON.parse(localStorage.getItem('user'))
formData.append("user_id", user.id)
this.loading = "Creating Invoice, please wait..."
console.log(this.invoice.total_price)
axios.post("http://localhost:3128/invoice", formData,
{
headers: {"x-access-token": localStorage.getItem("token")}
}).then(res => {
this.loading = ''
if (res.data.status === true) {
this.status = res.data.message
} else {
this.status = res.data.message
}
})
所有数据发回以表示正确,并送入发票表。当我在前端运行console.log时,它会记录发票名称,已付款,total_price。但是当我使用服务器console.log输入名称,已付款,total_price的req.body时,它仅返回已付款且名称,并且total_due未定义