【发布时间】:2019-05-02 04:59:27
【问题描述】:
我已经完成并尝试了教程,但结果是一样的
当我想用 axios 检索 API 时,结果同样难以辨认。
也许这可能是一个重复的问题,但我很困惑完成它。
请帮忙
这是我的代码
constructor(){
super();
this.state={
datas:[],
}
}
componentDidMount() {
axios
.get('/jobs')
.then(res => {
const updatedData = res.datas.map(data => {
return {
...data
};
});
this.setState({ datas: updatedData, err: null });
// console.log(response)
})
.catch(err => {
this.setState({ err: true });
});
}
从渲染端
render(){
let datas = <p style={{textAlign:'center'}}>Something went wrong!</p>
if(!this.state.err){
let datas = this.state.datas.map(data => {
return <Card
key={data.id}
desription={data.desription}
company={data.company}
/>
})
}
return(
<div>
<section>
<Navigation/>
</section>
<section>
<SearchBox></SearchBox>
</section>
<section>
<Category></Category>
</section>
<main>
{datas}
</main>
</div>
)
}
当我调用它时从控制台 here's the image
卡片组件图片: from card components
【问题讨论】:
-
这似乎是一个错字问题。试试
res.data而不是res.datas。 -
还是不行,先生..
标签: javascript reactjs axios fetch-api