如何在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页面中引入本地图片的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

vue和React状态管理有啥区别?

React子向父通信有哪些方法?

React中怎么改变state的值

React 生命周期函数有哪些

React用什么编辑器

React需要node吗

React怎么安装jquery

React设置文件路径别名的具体方法你知道么

React怎么mock数据

React native和React的区别是什么

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




打赏

取消

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

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

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

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

评论

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