import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' import { List } from 'antd-mobile' import { api } from '../../api/client.js' // 经济文章: 列表, 点进 /macro/articles/:slug // 使用 antd-mobile List 仿原生设置/通讯录样式 export default function ArticlesView() { const [articles, setArticles] = useState([]) const [err, setErr] = useState('') const [loading, setLoading] = useState(true) const navigate = useNavigate() useEffect(() => { let cancelled = false setLoading(true) api('/articles') .then((data) => { if (!cancelled) setArticles(data.articles || []) }) .catch((e) => !cancelled && setErr(e.message)) .finally(() => !cancelled && setLoading(false)) return () => { cancelled = true } }, []) if (loading) return
加载中...
if (err) return
{err}
if (!articles.length) return
暂无文章
return (
经济文章
{articles.map((a) => (
{a.date}
{a.excerpt}
} arrowIcon clickable onClick={() => navigate('/macro/articles/' + encodeURIComponent(a.slug))} /> ))}
) }