使用React写项目时报错了:
组件页面代码:
class App extends Component {
getStudentData = () => {
axios
.get('http://localhost:3000/api1/students')
.then(res => console.log(res))
.catch(err => {
console.log(err)
})
}
getCarData = () => {
axios
.get('http://localhost:3000/api2/cars')
.then(res => console.log(res))
.catch(err => {
console.log(err)
})
}
render() {
return (
<div>
<button onClick={this.getStudentData}>点我获取学生信息</button>
<button onClick={this.getCarData}>点我获取汽车信息</button>
</div>
)
}
}
以下规则是旧的,不好使了:
在src下创建配置文