【发布时间】:2021-08-01 22:34:12
【问题描述】:
节点版本:6.14.11, 操作系统
我希望能够像这样使用 'response from express' 和 'json from body-parser'.. 尽管如此,vscode 并没有打开我写的“导入代码”
我说的首先是我认为的问题。但我不能确定:(
import Axios from 'axios';
import { json } from 'body-parser';
import { response } from 'express';
import {React, useEffect} from 'react'
// import { FaCode } from "react-icons/fa";
import {API_URL, API_KEY} from '../../Config';
function LandingPage() {
useEffect(()=>{
const endpoint = `${API_URL}movie/popular?api_key=${API_KEY}&language=en-US&page=1`;
fetch(endpoint)
.then(response => response.json())
.then(response => console.log(response));
// Axios.get(endpoint)
// .then(response => {
// setMovies([...response.results])
// setMainMoveImage(response.results[0])
// })
// endpoint에 받은 값(API)을 fetch가 가져온다? 그렇게보면 될듯
// 그 값이 response에 담긴다. 하지만 response만으로 response을 읽을 수 없기에
// json()을 사용해줌.
},[])
return (
<>
<div style={{ width: '100%', margin: '0'}}>
{/* Main Image */}
<div style={{ width: '85%', margin: '1rem auto'}}>
<h2>Movies by latest</h2>
<hr />
{/* Movie Grid Cards */}
</div>
<div style={{ display: 'flex', justifyContent: 'center'}}>
<button>Load More</button>
</div>
</div>
</>
)
}
export default LandingPage
【问题讨论】:
-
这将有助于获取错误堆栈(文件名和行号)