import { Component } from 'react'; import ImagePreview from '../components/ImagePreview/ImagePreview'; import { Link } from '../components/SingleRouter/SingleRouter'; import Spinner from '../components/Spinner/Spinner'; import UserControl from '../components/UserControl/UserControl'; import { alert } from '../helper/alert'; import { apis } from '../helper/apis'; import { get } from '../helper/axios'; import { images } from '../resources.json'; import './index.css'; export class AppContainer extends Component { constructor(props) { super(props); this.state = { posts: [], fetchingEssential: false, }; } componentDidMount() { if (this.state.fetchingEssential) return; this.setState({ fetchingEssential: true }); get(apis.listEssence).then(({ data, status, networkStatus }) => { this.setState({ fetchingEssential: false }); if (networkStatus !== 200) return; if (!status) return alert('获取精选列表失败:' + data + ',请刷新重试'); this.setState({ posts: data }); }); } render() { return (
点击参加
精选留言
{ this.state.fetchingEssential ? (
) : ( this.state.posts.length === 0 ? (
暂时没有精选留言
) : (
{ this.state.posts.map((post, i) => (
头像
{post.nickname}
于{new Date(post.time * 1000).toLocaleString()}发布

{ post.image && (
) }
)) }
) ) }
); } }