我有一个渲染2个不同按钮的类。当我按下按钮时,将触发一个API调用,然后将该API调用的响应打印到控制台。但是,我真正想要的是呈现API调用的响应。我该如何实现?
class Form extends Component {
handleClick = async event => {
switch (event.target.id) {
case "createSalesOrder":
{
let res = await axios.post("http://localhost:5000/", {
buttonClicked: "createSalesOrder",
});
console.log(res.data);
break;
}
case "delete":
{
let res = await axios.delete("http://localhost:5000/delete");
console.log(res.data);
break;
}
default:
console.log("click didnt work");
}
};
render() {
return (
<div className='form'>
<h3>Delete all sales orders from SAP Sales Cloud which this webservice created</h3>
<Button variant="success" onClick={this.handleClick} id="createSalesOrder" >Create Sales Order</Button>
<br />
<br />
<Button variant="danger" onClick={this.handleClick} id="delete" >Delete Sales Order</Button>
</div>
);
}
}