0
我從服務器這樣如何訪問個人數據在JSON數據
[{
"_id": "588b3731d4428e2ff05ddefa",
"Id": 50,
"Name": "Vishruth",
"Age": 11
}, {
"_id": "588b45df255e323de55ac333",
"Id": 51,
"Name": "Vishruth",
"Age": 11
}]
如何從它
import React from 'react';
import axios from 'axios';
//require('./style.scss');
class Premontessori extends React.Component{
constructor(props){
super(props);
this.state={
post:[]
};
}
componentDidMount(){
let self = this;
axios.get('http://localhost:8080/list')
.then(function(data) {
console.log(data);
self.setState({post:data});
});
}
render(){
return(
<div>
{JSON.stringify(this.state.post.data)}
</div>
);
}
}
export default Premontessori;
我從服務器ComponentDidmount它沒有任何申報數據獲取數據。 –
componentDidMount(){ let self = this; (函數(data){ console.log(data); self.setState({post:data}); }); } –
我明白了,只是爲了演示目的,我已經定義了它。正如你所看到的,我只是映射this.state.post以及你如何訪問它。你可以忽略我在componentDidMount函數中改變的任何東西 –