如何在react页面中引入本地图片


当前第2页 返回上一页

(1)render()方法内定义为对象

1

2

3

4

5

6

7

8

9

const bgGround {

    display: 'inline-block',

    height: '40px',

    width: '40px',

    background: `url(${require("图片路径")})`

}

 

// 在return中使用

<span style={bgGround}>xxxxx</span>

(2)import引入

1

2

3

4

5

6

7

8

9

import imgUrl from '图片路径'

// render()中定义为对象

const bgGround = {

    display: 'inline-block',

    height: '40px',

    width: '40px',

    backgroundImage: 'url(' + imgUrl + ')'}

//在return中使用

<span style={bgGround}>xxxxx</span>

相关推荐:react教程

以上就是如何在react页面中引入本地图片的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

React移动端框架有哪些

redux如何关联React

React native的特点是什么

React native是什么框架?

React中怎么获取数据

vue和React有什么相似点

使用React native的好处是什么?

weex和React native区别是什么

前端React是什么

React jsx是什么

更多相关阅读请进入《React》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...