我通过以下代码片段来使用API:
constructor(props) {
super(props);
this.state = {
items: null
};
}
componentDidMount() {
return client
.get('/api/v1/product/list')
.then(response => {
this.setState({items: response});
return response
})
.catch(err => {
throw err
});
}
然后我从API得到了这样的结果:
我的问题是,如何过滤API结果,然后使用数据中的结果。?
答案 0 :(得分:1)
尝试这样,
constructor(props) {
super(props);
this.state = {
items: null
};
}
componentDidMount() {
return client
.get('/api/v1/product/list')
.then(response => {
//extract data from response
let {data} = response;
this.setState({items:data.results});
return response
})
.catch(err => {
throw err
});
}