【问题标题】:How can I display title, date according to ID?如何根据 ID 显示标题、日期?
【发布时间】:2022-06-13 21:17:07
【问题描述】:

我想根据文章 ID 显示标题和日期,但显示所有与 ID 不匹配的标题和日期。

我的代码

const getData = () => {
    const fetchArticle = profile.userId ? getNews : getAllNews;

    fetchArticle({ row: 10, page: 1 })
        .then((resolve) => {
            console.log(resolve);
            setNewsList(resolve.lists.map((news) => ({ ...news, newsId: news._id })));
        })
        .catch((reject) => {
            console.log(reject);
        });
    };
  
    useEffect(() => {
      getData();
    }, []);

然后在返回

{
newsList.map((news) => {
console.log(news.newsId);
return (
    <>
        <h2>{news.title}</h2>
        <p className={styles.publish}>Published On: {news.createdAt}</p>
    </>
);
})}

对不起,如果我不擅长写问题,因为我还是个初学者。谢谢

【问题讨论】:

  • 欢迎。请参阅How to Ask 并拨打tour 获取有关如何使用本网站的提示。

标签: reactjs next.js


猜你喜欢
  • 2022-06-14
  • 2012-07-14
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多