Api数据由于CORS -axios而未显示.ReactJS



我正在用这个链接调用steam review api: "api link">

我已经使用了另一个链接与我的代码,能够得到响应,甚至显示在我的屏幕上的数据,所以我没有错误的代码。我目前正在使用这个来尝试获得结果内容:comment.reviews.review

这是我的完整代码:

function Home() {
const [comments, setComments] = useState([]);
useEffect(() => {
fetchComments();
}, []);
useEffect(() => {
console.log(comments);
}, [comments]);
const fetchComments = async () => {
const response = await axios(
"https://store.steampowered.com/appreviews/1389990?json=1&language=english"
);
setComments(response.data);
};
var limitComments = comments.slice(0, 3);
return (
{limitComments &&
limitComments.map((comment) => (
<p>{comment.reviews.review}</p>

))}
);
}
export default Home;

请求有什么问题?我试过使用不同的键,如comment.author.reviews.review

您需要复习一下CORS,因为这是阻止您的请求成功的原因。这里有一个很好的资源:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

最新更新