码迷,mamicode.com
首页 > 其他好文 > 详细

react中 如何使用图片

时间:2020-01-25 19:29:13      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:port   应用   back   spl   div   play   font   dom   reac   

//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}/>
)

react中 如何使用图片

标签:port   应用   back   spl   div   play   font   dom   reac   

原文地址:https://www.cnblogs.com/alchemist-z/p/12233284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!