我是帖子列表的一部分。
render() {
const { posts, comments, emptyText, selectedImageToShow } = this.state;
return(
<React.Fragment>
{!posts.length ? <span>Список объявлений пуст</span> : posts.map((post, key) => (
<article key={post.id} className="uk-article uk-card uk-card uk-card-small uk-card-hover uk-card-body uk-border-rounded">
<h3>{post.title}</h3>
<div className="uk-grid uk-grid-small">
............
我在componentWillMount方法中获得了帖子列表
componentWillMount() {
this.getPosts();
}
getPosts(){
const { postIndex } = this.props;
getBuildingPosts(postIndex).then(response => {
if(response.status === 200){
this.setState({ posts: response.data });
}
});
}
添加或删除帖子时,我再次调用getPost方法。
postPost() {
....
addPublicPost(postcode,body).then(response => {
if(response.status === 200){
this.setState({emptyText: false});
UIKit.modal.alert('Успешно', {
labels: {
ok: 'Закрыть'
}
});
this.setState({selectedImageToShow: null, selectedImageToUpload: null});
this.getPosts();
}
})
更新帖子列表后,有时会出现错误: