如何使用 fetch 重写此方法?
How can I re-write this method using fetch?
在我的 React 应用程序中,我使用 axios 来请求服务器。
// This method will get the data from the database.
componentDidMount() {
axios
.get("http://localhost:3000/record")
.then((response) => {
this.setState({ records: response.data });
})
.catch(function (error) {
console.log(error);
});
}
如何使用 fetch 重写此方法?
fetch('http://localhost:3000/record')
.then(response => {
this.setState({ records: response.data });
})
.catch(function (error) {
console.log(error);
});;
如果您想使用其他请求方法,请勾选此link。
在我的 React 应用程序中,我使用 axios 来请求服务器。
// This method will get the data from the database.
componentDidMount() {
axios
.get("http://localhost:3000/record")
.then((response) => {
this.setState({ records: response.data });
})
.catch(function (error) {
console.log(error);
});
}
如何使用 fetch 重写此方法?
fetch('http://localhost:3000/record')
.then(response => {
this.setState({ records: response.data });
})
.catch(function (error) {
console.log(error);
});;
如果您想使用其他请求方法,请勾选此link。