React에서 local image file 사용하기

Eom Deokhyeon·2022년 11월 22일
0
post-thumbnail

📌 문제점

React에서 <img>를 사용하여 로컬 디렉토리에 저장되어 있는 이미지 파일을 불러오면 정상적으로 로드되지 않는다.

1. public 폴더 사용

<img src="/img/imgfile.png" />


2. import 사용

import imgfile from './imgfile.png';

<img src={imgfile} />


3. require 사용

<img src={require("./imgfile.png").default} />

0개의 댓글