构建基于前端的大学综合门户与价格管理系统
import React, { useState } from 'react';
import axios from 'axios';
function PriceTable() {
const [prices, setPrices] = useState([]);
useEffect(() => {
axios.get('/api/prices')
.then(response => setPrices(response.data))
.catch(error => console.error('Error fetching prices:', error));
}, []);
const handleUpdatePrice = (id, newPrice) => {
axios.put(`/api/prices/${id}`, { price: newPrice })
.then(() => {
const updatedPrices = prices.map(p =>
p.id === id ? { ...p, price: newPrice } : p
);
setPrices(updatedPrices);
})
.catch(error => console.error('Error updating price:', error));
};
return (
ID | Service Name | Current Price | Update Price |
---|---|---|---|
{price.id} | {price.serviceName} | {price.price} | handleUpdatePrice(price.id, e.target.value)} /> |
);
}
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!