我有一个网站用户列表,但是,每当我尝试通过Axios调用删除用户时,都会遇到HTTP 405错误。我认为这可能与我尝试使用ID的方式有关。
用户组件:
const Users = () => {
const [users, setUsers] = useState({ list: [] });
useEffect(() => {
axios
.get('/api/User')
.then(response => {
setUsers({list:response.data});
})
.catch(error => {
console.log(error);
})
}, []);
const handleDelete = () => {
axios
.delete('/api/User', users.list.id)
.then(response => {
console.log(response.status)
})
.catch(error => {
console.log(error)
})
}
return(
<div className="container white">
<h3 className="center"> User List</h3>
{users.list.map(item => (
<div className="section" key={item.id}>
<div className="divider"></div>
<h5>{item.username}</h5>
<h5>{item.email}</h5>
<button className="btn-delete" onClick={handleDelete}>Delete</button>
</div>
))}
</div>
);
}