react中 如何使用图片
时间:2020-01-25 19:02:13
收藏:0
阅读:99
//render
第一种方法:先const一个对象,把需要应用图片的dom上的style写入对象中, 然后在return()中使用style关键字赋值为预先定义的那个style对象
const bgGround = {
display:‘block‘,
height: ‘600px‘,
width:‘800px‘,
background: `url( ${require("../image/notfound404.jpg")})`
}
return(
<div style = { bgGround }></div>
)
第二种方法:直接import imgUrl from "../image/notfound404.jpg"
然后return()中 直接使用img标签,将url赋值为imgUrl
import imgUrl from "../image/notfound404.jpg"
return(
<img url = {imgUrl}/>
)
原文:https://www.cnblogs.com/alchemist-z/p/12233284.html
评论(0)