如何通過連接在 MongoDB 中的交付按鈕減少我的反應應用程式中的庫存
uj5u.com熱心網友回復:
如果單擊“已交付”按鈕,您將一一減少數量,然后將該值發送到后端并在資料庫中更新。以同樣的方式增加。
就像...
常量 stockQuantity = parseInt(products?.quantity) 常量 newStockQuantity = stockQuantity - 1;
然后
fetch(url, { method: 'PUT', // or 'PUT' headers: { 'Content-Type': 'application/json', }, body: JSON.stringify( { quantity: newStockQuantity, } ), }) .then(response => response.json()) .then(data => { console.log('Success:', data); toast('你的產品交付成功') setIsReload(!reload) })
uj5u.com熱心網友回復:
const delevary = e => {
const quantity = product?.quantity
const updateItem = {quantity}
const url = `http://localhost:7000//${id}`;
fetch(url,{
method : 'PUT',
headers : {
'content-type' : 'application/json'
},
body : JSON.stringify(updateItem)
})
.then(res => res.json())
.then (result =>{
console.log(result)
setIsreload(!isReload)
// setItems(result);
})
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/470767.html
上一篇:使用聯合洗掉一系列行的更快方法