我在React
尝试发送GET
请求的项目中遇到此编译错误:
./src/Component/Form.js
Module not found: Can't resolve '../axios' in 'F:\React\react-complete-guide\src\Component'
代码:
import React, {Component} from 'react';
import axios from '../axios';
class Form extends React.Component{
state={UserName:""};
onChangeHandle=(event)=>{
this.setState({UserName:event.target.value});
}
handleSubmit= (event) =>{
event.preventDefault();
console.log('form submit');
axios.get('https://api.github.com/users/${this.state.UserName}')
.then(
resp=>{
console.log(resp);
})
};
render(){
return(
<form onSubmit={this.handleSubmit}>
<input type="text"
placeholder="Github UserName"
value={this.state.UserName}
onChange={this.onChangeHandle} />
<br/>
<button type="submit"> Add card </button>
</form>
)}
}
export default Form;