我正在尝试使用 axios 从 api 获取数据,但出现此错误。我正在使用 django api。我的 api 似乎在邮递员上工作正常,但反应它给了我错误:
getStudentById(id) {
const url = `${API_URL}/api/student/student-detail/${id}`;
return axios.get(url);
}
componentDidMount() {
let urlId = this.props.match.params.id;
let thisComponent = this;
studentService.getStudentById(urlId)
.then(function (response) {
console.log(response.data.Name)
thisComponent.setState({
id: response.data.id,
name: response.data.Name,
enrollment_no: response.data.Enrollment_No,
registration_no:response.data.Registration_No,
semester: response.data.Semester,
year: response.data.Year,
course_nam: response.data.Course_Name,
course_code: response.data.Course_Code,
images: response.data.images
});
}).catch(error=>console.log(error))
}
答案 0 :(得分:0)
这些错误可能是由于以下原因引起的,请确保遵循以下步骤。将本地主机与本地虚拟机(主机)连接起来。在这里,我将 http://localhost:3001/ 连接到 http://abc.test 要遵循的步骤: