我在使用axios向react请求帖子时遇到了一些问题,代码如下
axios
.post("http://localhost/priangan/api/user/login", {
headers: {
"Content-type": "application/json; charset=UTF-8",
},
data: {
username: this.state.username,
password: this.state.password,
},
}).then((response) => {
if (response.status == 200) alert("Login Success");
});
但是当我请求时,控制台中出现了一些错误,如下所示
error in console
,找不到本地主机
然后我尝试使用fetch,代码如下
fetch("http://localhost/priangan/api/user/login", {
method: "POST",
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
}),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
}).then((response) => {
if (response.status == 200) alert("Login Success");
});
其工作,
那么我在使用axios时有什么问题呢?
谢谢你帮我