我正在制作一个网络应用程序来获取最新的新闻更新,但在部署它后遇到问题。该应用程序在本地主机上完美运行并从 newsapi 获取所有数据,但是当我将其部署在 firebase 或 github 上时,axios 无法获取 api 或将其显示在屏幕上。这是我的 github 存储库的链接。
import React, {useState, useEffect } from "react";
import NewsArt from "../NewsArt";
import axios from "axios";
function AllNews(props) {
const [data, setData] = useState({ articles: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://newsapi.org/v2/top-headlines?country=us&apiKey=09a334ba3fbe41acaff79515476dc4cc',
);
setData(result.data);
};
fetchData();
}, []);
return (
<div>
<ul>
{data.articles.map(item => (
<NewsArt
title= {item.title}
urlToImage = {item.urlToImage}
description = {item.description}
url = {item.url}
publishedAt = {item.publishedAt}
author = {item.author} />
))}
</ul>
</div>
);
}
export default AllNews;
mgur.com/vltyv.png
12345678_0001
相关分类