Mysql 如何从数据库中获取特定的api?
}Mysql 如何从数据库中获取特定的api?,mysql,node.js,reactjs,Mysql,Node.js,Reactjs,} 如何通过发送带有URL的所需ID从数据库中获取特定数据?您可以使用javascript中的格式字符串语法,并使用该语法将ID添加到URL字符串中 componentDidMount() { fetch("http://localhost:5000/customers/:id") .then((res) => res.json()) .then((info) => { this.setState({ info }); }) .then(
如何通过发送带有URL的所需ID从数据库中获取特定数据?您可以使用javascript中的格式字符串语法,并使用该语法将ID添加到URL字符串中
componentDidMount() {
fetch("http://localhost:5000/customers/:id")
.then((res) => res.json())
.then((info) => {
this.setState({ info });
})
.then((err) => console.log(err));
例如,如果我在表单中使用ID登录,如何在单击“登录”时将表单ID添加到URL?
const id = 42
fetch(`http://localhost:5000/customers/${id}`)