Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In JSX, how do you reference a value from props from inside a quoted attribute value?(在JSX中,如何从带引号的属性值中引用props值?)

For example:(例如:) <img className="image" src="images/{this.props.image}" /> The resulting HTML output is:(生成的HTML输出是:) <img class="image" src="images/{this.props.image}">   ask by cantera translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
217 views
Welcome To Ask or Share your Answers For Others

1 Answer

React(或JSX)不支持在属性值内部进行变量插值,但是您可以将任何JS表达式放在花括号中作为整个属性值,因此这适用于:

<img className="image" src={"images/" + this.props.image} />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...