import React from 'react';
import axios from 'axios'
class Axios extends React.Component {
constructor() {
super();
this.state = {
res: [],
isShow: false
}
}
getData = () => {
var api = 'http://192.168.3.166:8088/entityList/querAircraftCarrier';
axios.get(api)
.then(response => {
console.log(response);
this.setState({
res: response.data.rows
})
})
.catch(function (error) {
console.log(error);
});
}
render() {
return (
<div>
<h2>axios获取数据</h2>
<button onClick={this.getData}>获取api接口</button>
{this.state.res.map(item => (
<div key={item.id}>
<span>{item.name}</span><span>{item.state}</span>
</div>
))}
</div>
)
}
}
export default Axios;