最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to concatenate an img src in React? - Stack Overflow

programmeradmin0浏览0评论

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.

<img src=`/{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:

media/19633/btc.png

Am I concatenating incorrectly or is this just not possible?

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.

<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:

media/19633/btc.png

Am I concatenating incorrectly or is this just not possible?

Share Improve this question edited Jan 22, 2018 at 8:24 mplungjan 178k28 gold badges180 silver badges240 bronze badges asked Jan 22, 2018 at 8:19 anbhdanbhd 1253 silver badges12 bronze badges 1
  • Flagged as This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. – Dez Commented Jan 22, 2018 at 8:22
Add a comment  | 

2 Answers 2

Reset to default 14

You've missed $ sign and brackets for attribute

<img src={`https://www.cryptocompare.com/${this.state.cryImage}`} />

You forgot to add {} in src prop:

<img src={`https://www.cryptocompare.com/${this.state.cryImage}`} />
发布评论

评论列表(0)

  1. 暂无评论