[英]Is it possible to concatenate an img src in React?
This might be a silly question but I'm trying to concatenate the source of an image in React to be rendered on the screen, but it's not working. 这可能是一个愚蠢的问题,但我试图连接React中的图像源以在屏幕上呈现,但它不起作用。
<img src=`https://www.cryptocompare.com/{this.state.cryImage}` />
In this.state.cryImage, I only get the second half of the link (I'm pulling data from an API) so for example it would be something like: 在this.state.cryImage中,我只得到链接的后半部分(我从API中提取数据)所以例如它会是这样的:
media/19633/btc.png
Am I concatenating incorrectly or is this just not possible? 我连接不正确还是这不可能?
您错过了$ sign和属性括号
<img src={`https://www.cryptocompare.com/${this.state.cryImage}`} />
你忘了在src
prop中添加{}
:
<img src={`https://www.cryptocompare.com/${this.state.cryImage}`} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.