DOMException:无法在"XMLHttpRequest"上执行'open':反应中的URL无效



苏/大师,帮我

componentDidMount() {
axios
.get(API_URL + "products")
.then((res) => {
const menus = res.data;
this.setState({ menus });
})
.catch((error) => {
console.log(error);
});

}

render() {
console.log(this.state.menus);
return (

以及我在本地服务器中的API

export const API_URL = "http://localhost:3004";

这是我的问题在此处输入图像描述

您的结果URL是"http://localhost:3004products",您必须在API_URL 之后附加"/">

可能是它正在以"http://localhost:3004products",在URL之间添加"/"。

在产品之前或API_URL 的URL之后添加"/">

componentDidMount() {
axios
.get(API_URL + "/products")   // Change
.then((res) => {
const menus = res.data;
this.setState({ menus });
})
.catch((error) => {
console.log(error);
});

最新更新